Capturing the "Delete Key"
OK folks.
I have a control and wish ti capture the "Delete Key".
I first tried this :
Code:
private void desktopThumbs_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == 127)
{
MessageBox.Show("DELETE HIT");
}
}
And nothing. Literaly nothing happens no matter what keys I hit.
I then tried this :
Code:
private void desktopThumbs_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Delete)
{
MessageBox.Show("DELETE HIT");
}
}
And this event does fire when I hit most keys but not the "Delete" key.
How do I capture the delete key ?
Thanks In Advance
Re: Capturing the "Delete Key"
KeyPress is meant to capture only alphanumeric characters. For special characters, you need either KeyDown or KeyUp event.
So your second try should work. Adding to this, I'd suggest you to set the KeyPreview Property of the Form/Control (if it exposes) to True. Just give it a try.
Re: Capturing the "Delete Key"
No joy I'm afraid.
There is no keypreview property and that damn "Del" key never ever seems to fire off the KeyDown event.
This is driving me nuts.:mad:
Re: Capturing the "Delete Key"
What kind of control is it?
I just tried with a checkbox and a textbox and both of those showed the messagebox.
Re: Capturing the "Delete Key"
Its a thumbnail third party control which displays thumbnails of tiff files.
Still don't get it. Why is the Del key causing me grief. grrrr:mad: