我有一个 while 循环,我希望我的程序在用户激活表单时运行。现在我都试过了,
While frmLineProduct.ActiveForm.Focus = True
While (frmLineProduct.ActiveForm.Equals(True))
但这些都不起作用。我将继续阅读此内容,但如果有人已经知道如何做到这一点,我将不胜感激。
您可以实现几个事件来控制状态,例如:
Public Property HasFocus As Boolean = True 'global flag
Private Sub Form_Deactivated(sender As Object, e As System.EventArgs) _
Handles Me.Deactivated
_hasFocus = False
End Sub
Private Sub Form_Activated(sender As Object, e As System.EventArgs) _
Handles Me.Activated
_hasFocus = True
End Sub
然后在您的代码中:
While Form.Hasfocus
Application.DoEvents 'a work-around for receiving events while in a while