KeyPress Event in VB.NET
The KeyPress event is used in the Windows Form when a user presses a character, space, or backspace key during the focus on the control, the KeyPress event occurs. Furthermore, the keypress event is raised only when printable keys or numbers such as alphabets (a, b, c) are processed with Windows Form. It is not picked up by non-character keys such as Esc, Shift, Ctrl, etc. to raise the KeyPress event. The Non-character keys are used with KeyDown and KeyUp events in the VB.NET Windows application.
KeyDown event: The KeyDown event occurred when a user presses a key on the keyboard. It repeats while the user keeps the key depressed. The KeyDown event is provided by the Keyboard event in the VB.NET application.
KeyUp event: The KeyUp event is rising when a user releases a key on the keyboard. The KeyUp event is provided by the Keyboard event in the VB.NET application.
Let's create a simple program to display the KeyPressEvent in the VB.NET Windows Forms.
Press any printable key. We have pressed the key A.
After inserting a character, click on the Press button, it shows the following output.
Example of KeyDown Event
Let's create a simple program to display the use of KeyDown events in the VB.NET Windows Forms.
Press the Enter button, it shows the image shown below.
Example of KeyUp Event
Let's create a simple program to display the use of KeyUp events in the VB.NET Windows Forms.
After releasing the Enter key from the keyboard, it displays the image below.