have been struggling to achieve this problem, today inadvertently found on the form has keypriview this property
After finding the relevant information, understand that it is used for the form snap key pressed on the keyboard
This feature can be easily implemented by setting this property to True as soon as you create a new form.
Method One:
Use commit as Me.keydown to complete
Private SubForm_keypress (Sender as ObjectE asKeyEventArgs)Handles Me. KeyDownIfE.keycode = Keys.escape Then DimMessge as NewMSG Messge.head.Text="Coming out of the system"MESSGE.MSGP.Text="Press ENTER to exit the system, ESC to return ..."Messge. Show ()End If IfE.keycode = keys.f4 Then DimMessge as NewMSG Messge.head.Text="F4"MESSGE.MSGP.Text="You pressed the F4."Messge. Show ()End If IfE.keycode = Keys.f5 Then DimMessge as NewMSG Messge.head.Text="F5"MESSGE.MSGP.Text="You pressed the F5."Messge. Show ()End If End Sub
This makes it easy to capture all keys on the keyboard
ESC Example:
F4 Example
F5 Example
Here is another example of a method: Handles Me.keypress
Private SubForm_keypress (Sender as ObjectE asKeyPressEventArgs)Handles Me. KeyPressIfE.keychar = ChrW ( -) Then DimMessge as NewMSG Messge.head.Text="Coming out of the system"MESSGE.MSGP.Text="Press ENTER to exit the system, ESC to return ..."Messge. Show ()End If IfE.keychar = CHR ( the) Then DimMessge as NewMSG Messge.head.Text="F4"MESSGE.MSGP.Text="You pressed the F4."Messge. Show ()End If IfE.keychar = CHR ( the) Then DimMessge as NewMSG Messge.head.Text="F5"MESSGE.MSGP.Text="You pressed the F5."Messge. Show ()End If End Sub
Unfortunately, this is not the way to capture F1-f12, and some special keys, such as shift and so on.
Of course, it can also be achieved with handles Me.keyup.
vb.net snapping keys pressed on a keyboard on a form rather than on a TextBox control