This project has moved and is read-only. For the latest updates, please go here.

Disabling caption editing on shape

Jul 15, 2014 at 11:50 AM
Hi

Is it possible to hide the caption editing box and disable caption editing when user clicks on the shape?


Thanks,
Zvonko
Jul 16, 2014 at 8:33 AM
You can revoke the "Permission.Data" permission, you can derive Shapes from the standard shapes that override the properties and methods of ICaptionedShape, e.g. return 0 for CaptionCount, return -1 for FindCaptionFromPoint, etc.
Finally, you could try to overwrite the display's explicit implementation of IDiagramPresenter.OpenCaptionEditor, or change the display's code (DoOpenCaptionEditor) or the tool's code (SelectionTool.IsEditCaptionFeasible).
Aug 25, 2014 at 7:29 AM
Hi

I followed your instructions and override the necessary members (FindCaptionFromPoint, CaptionCount).

Now when I press F2 when the shape is selected, I get the following exception:

Specified argument was out of the range of valid values. Parameter name: captionIndex
at Dataweb.NShape.WinFormsUI.InPlaceTextBox.Construct(IDiagramPresenter owner, ICaptionedShape shape, Int32 captionIndex, String currentText, String newText)

Aug 26, 2014 at 8:48 AM
Edited Aug 26, 2014 at 8:49 AM
Thanks for the feedback.
This issue is a bug in the display component. It will be fixed with the next release.

If you want to fix it yourself, open WinformsUI\Display.cs and search for
protected override void OnKeyDown(KeyEventArgs e) {
Replace this code
case Keys.F2:
    if (Diagram != null
        && SelectedShapes.Count == 1
        && Project.SecurityManager.IsGranted(Permission.Data, SelectedShapes.TopMost)
        && SelectedShapes.TopMost is ICaptionedShape) {
        ICaptionedShape captionedShape = (ICaptionedShape)SelectedShapes.TopMost;
        DoOpenCaptionEditor(captionedShape, 0, string.Empty);
        e.Handled = true;
    }
    break;
with this code:
case Keys.F2:
    if (Diagram != null
        && SelectedShapes.Count == 1
        && Project.SecurityManager.IsGranted(Permission.Data, SelectedShapes.TopMost)
        && SelectedShapes.TopMost is ICaptionedShape) {
        ICaptionedShape captionedShape = (ICaptionedShape)SelectedShapes.TopMost;
        if (captionedShape.CaptionCount > 0) {
            DoOpenCaptionEditor(captionedShape, 0, string.Empty);
            e.Handled = true;
        }
    }
    break;