0

我有一个 while 循环,我希望我的程序在用户激活表单时运行。现在我都试过了,

While frmLineProduct.ActiveForm.Focus = True
While (frmLineProduct.ActiveForm.Equals(True))

但这些都不起作用。我将继续阅读此内容,但如果有人已经知道如何做到这一点,我将不胜感激。

4

2 回答 2

1

您可以实现几个事件来控制状态,例如:

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
于 2012-11-09T16:27:52.637 回答
0

答案最终成为了一种我以前从未听说过的方法,但我的其他帖子中的某个人将我引向了它。

Control.Invoke 方法(委托,Object())

有兴趣的可以在这里找到答案

于 2012-12-10T12:18:05.110 回答