[ACCEPTED]-Check if DELETE key is pressed?-visual-studio
The KeyEventArgs object contains a member called "KeyCode" that 8 you can compare to the "Keys" enumeration.
Note 7 that certain keys may not raise the KeyDown 6 event if they are handled by the default 5 windowing system. I'm not sure, and I can't 4 check it right now, but you may not get 3 the KeyDown event for keys like Tab, Delete, Enter, etc.
You 2 can usually do something like this (this 1 is C#, not VB, but should be similar):
public void MyControl_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Delete)
{
// delete was pressed
}
}
If you set KeyPreview property of form then form 7 will receive key events before the event 6 is passed to the control that has focus. For 5 example if you have textboxes and buttons 4 on the form, normally they(the control that 3 has focus) will capture the key press event. So 2 make sure to set KeyPreview=true
Use this to capture the 1 key code.
Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
If e.KeyCode = Keys.Delete Then
'todo
End If
End Sub
Compare e.keyValue
with Keys.Delete
0
More Related questions
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.