KeyPress Event
Applies To
TextBox
Description
Occurs when a key is pressed.
Usage
Form_Control_KeyPress (Sender$ As String, ByRef Key$ As String)
- Sender$
- Name of a control that sent the event.
- Key$
- The key that was pressed by the operator.
Remarks
The Keypress event can be used to detect the keys that are input by the operator.
This event can be used as a filter. You can change the key that was pressed by setting Key$ to another character. You can cancel a keypress by setting Key$ to an empty string.
See Also
TextBox
Example
Function frmMain_txtSpeed_KeyPress(Sender$ As String, ByRef Key$ As String)
' Allow only digits to be entered
If Instr("0123456789" Key$) < 0 Then
Key$ = ""
EndIf
Fend