如果把窗体的KeyPreview属性设为True,那么窗体将比其内的控件优先获得键盘事件的激活权。比如窗体Form1和其内的文本框Text1都准备响应KeyPress事件,那么以下代码将首先激活窗体的KeyPress事件: Private Sub Form_Load() Me.KeyPreview = TrueEnd Sub Private Sub Form_KeyPress(KeyAscii As Integer) MsgBox "这是窗体的KeyPress事件"End Sub Private Sub Text1_KeyPress(KeyAscii As Integer) MsgBox "这是文本框的KeyPress事件"End Sub
时间: 2024-10-28 15:35:05