Profile Picture

Stop Delete key from firing

Posted By Craig Browder 10 Years Ago
Author
Message
Craig Browder
Posted 10 Years Ago
View Quick Profile
Forum Newbie

Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)

Group: Forum Members
Last Active: 10 Years Ago
Posts: 9, Visits: 17
I cannot stop the delete key from firing. can you please take a look at the code below and let me know what I am doing incorrectly?
I over-rode the ProcessCmdKey method because NodeKeyPress didn't detect the delete key being pressed.


protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
if (keyData == Keys.Delete)
{
EventSinkService_NodeKeyPress(new NKeyPressEventArgs(this.nDrawingView1, (char)keyData));

keyData = Keys.Space;
}

return base.ProcessCmdKey(ref msg, keyData);
}

void EventSinkService_NodeKeyPress(NKeyPressEventArgs args)
{
if (this.ReadOnly == true)
{
if (args.KeyChar == (Char)Keys.Delete)
args.Handled = true;
}
}

Nevron Support
Posted 10 Years Ago
View Quick Profile
Supreme Being

Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)

Group: Forum Members
Last Active: 1 days ago @ 1:54 AM
Posts: 3,054, Visits: 4,009

The code you have used to disable shape deleting with the “Delete” key is not correct. There are 2 better ways to achieve this functionality in Nevron Diagram For .NET.

1. The first way (which is the one I recommend) is to set “Delete” protection to all shapes you want to forbid removing of. The following code demonstrates how to set “Delete” protection to all shapes in the active layer of a drawing document:

NNodeList shapes = document.ActiveLayer.Descendants(NFilters.TypeNShape, -1);

for (int i = 0, count = shapes.Count; i < count; i++)

{

      NShape shape = (NShape)shapes[i];

      NAbilities protection = shape.Protection;

      protection.Delete = true;

      shape.Protection = protection;

}

Note that setting a “Delete” protection will show a message to the user when he tries to delete a shape with the “Delete” keyboard key. If you don’t want this message to be shown, you can set the ShowMessage property of the drawing view to false:

view.ShowMessages = false;

2. The second way to disable shape from deleting is to use the NodeRemoving event of the drawing document’s event sink service and set the Cancel property of the event arguments to true.

document.EventSinkService.NodeRemoving += OnNodeRemoving;

 

private void OnNodeRemoving(NChildNodeCancelEventArgs args)

{

      args.Cancel = true;

}

In general all the “...ing” events of the event sink service are cancellable, so you can cancel them in this way when necessary.



Best Regards,
Nevron Support Team





Similar Topics


Reading This Topic