Saturday, January 5, 2013

KEYPRESS EVENT IN VB.NET


Handle Keyboard Input at the Form Level in VB.NET
Windows Forms processes keyboard input by raising keyboard events in response to Windows messages. Most Windows Forms programs process keyboard input by handling the keyboard events.

How do I detect keys pressed in VB.NET
You can detect most physical key presses by handling the KeyDown or KeyUp events. Key events occur in the following order:
  KeyDown
  KeyPress
KeyUp
 
Note: Before a form can capture its key-related events, its keyPreview property MUST be set to TRUE
 
How to detect when the Enter Key Pressed in VB.NET
The following VB.NET code behind creates the KeyDown event handler. If the key that is pressed is the Enter key, a MessegeBox will displayed .

  If e.KeyCode = Keys.Enter Then
 MsgBox("enter key pressd ")
End If

How to get TextBox1_KeyDown event in your VB.Net source file ?
Select your VB.Net source code view in Visual Studio and select TextBox1 from the top-left Combobox and select KeyDown from top-right combobox , then you will get keydown event sub-routine in your source code editor.

  Private Sub TextBox1_KeyDown(...)..
End Sub

No comments:

Post a Comment