查看: 19  |  回复: 0
  VB6 判断某控件是否有焦点,子程序 s_IsFocus()
楼主
发表于 2024年10月16日 17:11

新建From1(窗体),新建Command1-2(按钮CommandButton),代码:

Private Sub Command1_Click()
    Call s_IsFocus
End Sub

Private Sub Command2_Click()
    Call s_IsFocus
End Sub

Private Sub s_IsFocus()
    If Form1.ActiveControl Is Command2 Then  'Command2是被判断的控件
        MsgBox "有焦点"
    Else
        MsgBox "无焦点"
    End If
End Sub

当然也可以用timer控件不断检查。

您需要登录后才可以回帖 登录 | 立即注册
【本版规则】请勿发表违反国家法律的内容,否则会被冻结账号和删贴。
用户名: 立即注册
密码:
2020-2024 MaNongKu.com