2

这是我得到的代码,它没有错误,但似乎不起作用。能以某种方式告诉我它有什么问题吗?

        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
4

1 回答 1

1

与其使用我认为不太适合 Forms 的 Focused,不如尝试使用Form.ActiveForm

    Dim frmCurrentForm As Form

    frmCurrentForm = Form.ActiveForm
    If Not frmCurrentForm Is Nothing Then
        Dim action As Action(Of Form)
        action = Sub(form)
                     Dim failedLoginForm As New Form2
                     failedLoginForm.setError("failed blah blah")
                     failedLoginForm.StartPosition = FormStartPosition.CenterParent
                     failedLoginForm.ShowDialog(form)
                 End Sub

        If (frmCurrentForm.InvokeRequired) Then
            frmCurrentForm.Invoke(action, New Object() {frmCurrentForm})
        Else
            action(frmCurrentForm)
        End If
    End If
于 2013-07-03T01:23:16.013 回答