The Key handling events will work only when a key is pressed while the form has focus.
The Form properties events and methods are described in http://www.tutorialspoint.com/vb.net/vb.net_forms.htm. the following code will display the pressed key name(vb.net) in message box
Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
MsgBox(e.KeyCode.ToString)
End Sub
You can trace out the Print screen key's press by using the following code:
Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
If e.KeyCode = Keys.PrintScreen Then
MsgBox("Print screen key is pressed")
End If
End Sub
Note :- This will not work in laptops in which the PrintScreen
is achieved through function key.
For key code reference: http://msdn.microsoft.com/en-in/library/aa243025(v=vs.60).aspx
I think their is no problem with your code the reason is that your form doesn't have focus while the key is pressed.
The tab index 0
is assigned to any other control in the form so the initial focus will set to that control
Sorry am not so good in C#, you can refer http://converter.telerik.com/ for code conversion