We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Avoiding the deletion of a shape in a diagram when DELETE key is pressed

Hello for everybody.

In the application that I am developing, the user can select any kind of shape drawn in the diagram, and then, press the DELETE key.

I have seen when I press the DELETE key and exists a shape selected, this is deleted. But I need first to detect the code of the DELETE key BEFORE of the deletion of the shape, in another words, I need the shape don't be deleted in spite of the user presses the DELETE key (the user can decide if the shape should be deleted).

I have intended to do that by using handles for the diagram's events PreviewKeyDown,KeyUp, KeyDown and Keypress, but I can't obtained the desired operation.

I wonder if you could help to me. Thanks


4 Replies

RA Ron Alan Sawyer October 23, 2008 11:01 PM UTC

In the Key up event of the diagram component check to see if the KeyEventArgs.KeyCode is equal to Keys.Delete. Something like:

private void diagramComponent_KeyUp(object sender, KeyEventArgs e)
{
string ii;
if (e.KeyCode == Keys.Delete)
{
DoStuff();
}
}




AD Administrator Syncfusion Team October 24, 2008 12:29 PM UTC

Hi RAS.

I have probed the KeyUp method, but I really need that when the user select a shape in the diagram and press the DELETE key, the shape doesn't be deleted.

Is there any form to configure the diagram for avoiding the deletion of shapes because of the press of DELETE key?

Thanks.



RA Ron Alan Sawyer October 24, 2008 09:33 PM UTC

OK, I looked at this a little more closely.

On your form, set KeyPreview to true.

In your form's KeyDown event put the following code:

if (e.KeyCode == Keys.Delete)
e.Handled = true;
This will prevent the delete key from being passed to the diagram control and your symbol will not be deleted.



AD Administrator Syncfusion Team October 27, 2008 01:35 PM UTC

I have probed it, and it works correctly. Tnaks


Loader.
Live Chat Icon For mobile
Up arrow icon