Keydown event

  • Thread starter Thread starter win
  • Start date Start date
W

win

I'm convert a VB6 program to .Net platform.
My program use function key (F12) to close a form.
Now I found that the coding in the keydown event of control triggered, the
coding in the keydown of the form does not triggered.

Can anyone help me?
Thanks a lot.
 
win said:
I'm convert a VB6 program to .Net platform.
My program use function key (F12) to close a form.
Now I found that the coding in the keydown event of control
triggered, the coding in the keydown of the form does not triggered.


Set the Form's KeyPreview property to True. (like it was in VB6)


Armin
 
I'm convert a VB6 program to .Net platform.
My program use function key (F12) to close a form.
Now I found that the coding in the keydown event of control triggered, the
coding in the keydown of the form does not triggered.

Can anyone help me?
Thanks a lot.

While your form active, that code must work:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
If e.KeyCode = Keys.F12 Then
Me.Close()
End If
End Sub
 
While your form active, that code must work:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
If e.KeyCode = Keys.F12 Then
Me.Close()
End If
End Sub

Note: When there's nothing on form like buttons, listboxes or others,
this code works. But if there are some other controls placed on form,
i don't know the reason that it doesn't work, maybe focusing problem?
 
win said:
I'm convert a VB6 program to .Net platform.
My program use function key (F12) to close a form.
Now I found that the coding in the keydown event of control triggered, the
coding in the keydown of the form does not triggered.

Either set the form's 'KeyPreview' property to 'True' or add a mainmenu
component with a menu item which has the appropriate shortcut.
 
Win,

As forever about this question I ask another question, why the keydown and
not the keyup, that one gives a lot of information which keys have been
pressed.

Cor
 
Back
Top