KeyPress事件

适用范围
TextBox

描述
按下按键时发生。

使用

Form_Control_KeyPress (Sender$ As String, ByRef Key$ As String)  
Sender$
被设置为引发事件的控件的名称。
Key$
按下按键的字符串。

备注
Keypress事件可用于检测操作员输入的按键。
此事件可用作过滤器。通过将Key$设置为其他字符可更改按下的按键。通过将Key$设为空字符串可取消keypress响应。

另见
TextBox

示例

Function frmMain_txtSpeed_KeyPress(Sender$ As String, ByRef Key$ As String)  
  ' 仅允许输入数字  
  If Instr("0123456789" Key$) < 0 Then  
    Key$ = ""  
  EndIf  
Fend