如果把窗体的KeyPreview属性设为True,那么窗体将比其内的控件优先获得键盘事件的激活权。比如窗体Form1和其内的文本框Text1都准备响应KeyPress事件,那么以下代码将首先激活窗体的KeyPress事件:

Private Sub Form_Load()
Me.KeyPreview = True
End Sub

Private Sub Form_KeyPress(KeyAscii As Integer)
MsgBox "这是窗体的KeyPress事件"
End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer)
MsgBox "这是文本框的KeyPress事件"
End Sub

相关文章:

  • 2021-07-20
  • 2022-02-18
  • 2021-12-18
  • 2021-05-26
  • 2021-12-05
  • 2021-08-05
  • 2021-07-18
  • 2021-08-07
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-12-27
  • 2022-12-23
  • 2021-10-08
  • 2021-12-02
  • 2022-12-23
相关资源
相似解决方案