這是我起牀的代碼,它沒有錯誤,但它似乎沒有工作。可以以某種方式告訴我它有什麼問題嗎?如何在不同的線程中使用Application.OpenForms的代理
Dim frmCurrentForm As Form
Dim wasFocused As Boolean = False
For Each frmCurrentForm In Application.OpenForms
If Not frmCurrentForm Is Nothing Then
Dim action As Action(Of Form)
action = Sub(form)
If form.Focused() Then
Dim failedLoginForm As New frmFailedLogin
failedLoginForm.setError("failed blah blah")
'failedLoginForm.Parent = form
failedLoginForm.StartPosition = FormStartPosition.CenterParent
failedLoginForm.ShowDialog()
wasFocused = True
End If
End Sub
If (frmCurrentForm.InvokeRequired) Then
frmCurrentForm.Invoke(action, New Object() {frmCurrentForm})
Else
action(frmCurrentForm)
End If
If wasFocused Then
Exit For
End If
End If
Next
什麼不起作用?是否有特定的錯誤信息? –
'.Focused()'從來不會在我關注的任何表單上觸發。我認爲也許是因爲我是突破點,而且在斷點被擊中的時候沒有集中注意力。但是我沒有把斷點關掉並且完全關注表單並且仍然不會彈出'failedLoginForm'。也許你知道更容易做到這一點的原因,我希望failedLoginForm在當前關注的任何表單的中心彈出。 – SSpoke