vb.net snapping keys pressed on a keyboard on a form rather than on a TextBox control

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.