Vb.net 如何使用.Show()方法,让用户能够';是否单击已在后台打开的其他表单?

Vb.net 如何使用.Show()方法,让用户能够';是否单击已在后台打开的其他表单?,vb.net,winforms,show,showdialog,Vb.net,Winforms,Show,Showdialog,现在,我使用了“jobdone”标志和以下行为(对我来说,这看起来非常可怕…): 如果我尝试使用ShowDialog(),行为会更好,但管理所有打开和关闭窗口(如果窗体多)是一个问题,我注意到,如果关闭一个ShowDialog()窗体,所有已打开的后台窗体都会自动关闭 谢谢运行了一个快速测试,效果非常好: Public Sub ForceOpen(ByRef frm As Form) frm.Show() For Each otherForm As Form In Applica

现在,我使用了“jobdone”标志和以下行为(对我来说,这看起来非常可怕…):

如果我尝试使用ShowDialog(),行为会更好,但管理所有打开和关闭窗口(如果窗体多)是一个问题,我注意到,如果关闭一个ShowDialog()窗体,所有已打开的后台窗体都会自动关闭


谢谢

运行了一个快速测试,效果非常好:

Public Sub ForceOpen(ByRef frm As Form)
    frm.Show()
    For Each otherForm As Form In Application.OpenForms
        If otherForm Is frm Then
            AddHandler frm.FormClosing, AddressOf BlockFormClosing
        Else
            otherForm.Enabled = False
        End If
    Next
End Sub

Public Sub BlockFormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs)
    e.Cancel = True
End Sub

Public Sub EnableOpenForms()
    For Each frm As Form In Application.OpenForms
        frm.Enabled = True
        RemoveHandler frm.FormClosing, AddressOf BlockFormClosing
    Next
End Sub

呼叫表单将使用
ForceOpen(FormStayOpen)
打开保持开放表单。当“保持打开”窗体允许用户关闭它的条件得到满足时,让它调用
EnableOpenForms()

窗体可以是模态的,也可以是非模态的。你到底想实现什么?我想要一个清晰的方法来打开表单,当打开其他按钮时,通常无法打开/单击;或者我需要一种方法来防止在模态窗体关闭时关闭调用(已打开)窗体对不起,英语不是我的母语,所以我听不懂你在说什么。我想我会让英语水平更好的人来处理的。绝对不要绕圈子。一定要做ShowDialog.FWIW,我认为你的代码应该是
而不是NewLoginForm.jobdone=False)
(或者干脆是
而不是NewLoginForm.jobdone
)。无论如何,我给你的答案使用了一种完全不同的方法,所以除非你出于某种原因不能使用它,否则这是一个没有意义的观点。
Public Sub ForceOpen(ByRef frm As Form)
    frm.Show()
    For Each otherForm As Form In Application.OpenForms
        If otherForm Is frm Then
            AddHandler frm.FormClosing, AddressOf BlockFormClosing
        Else
            otherForm.Enabled = False
        End If
    Next
End Sub

Public Sub BlockFormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs)
    e.Cancel = True
End Sub

Public Sub EnableOpenForms()
    For Each frm As Form In Application.OpenForms
        frm.Enabled = True
        RemoveHandler frm.FormClosing, AddressOf BlockFormClosing
    Next
End Sub