在VB.net中处理多个对话框

时间:2017-08-08 19:43:25

标签: vb.net forms

我对我如何在VB.net应用程序中处理一系列对话框感到有些困惑。例如,我有4个表单,每个表单都有一个简单的标签,随后从前一个标签作为对话框调用。

第一种形式:

Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Dim frm As New Form2
    Form2.ShowDialog(Me)
End Sub
End Class

第二种形式:

Public Class Form2
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Dim frm As New Form3
    frm.ShowDialog(Me)
End Sub

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
    Dim cls As New LabelFlash
    cls.Flash()
End Sub
End Class

第三种形式:

Public Class Form3
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Dim frm As New Form4
    frm.ShowDialog(Me)
    Me.DialogResult = Windows.Forms.DialogResult.OK
End Sub

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
    Dim cls As New LabelFlash
    cls.Flash()
End Sub
End Class

第四种形式:

Public Class Form4
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Dim cls As New LabelFlash
    cls.Flash()
End Sub
End Class

他们所引用的类只是切换每个表单上标签的可见性:

Public Class LabelFlash
Sub Flash()
    If Form1.Label1.Visible = False Then
        Form1.Label1.Visible = True
    Else
        Form1.Label1.Visible = False
    End If

    If Form2.Label1.Visible = False Then
        Form2.Label1.Visible = True
    Else
        Form2.Label1.Visible = False
    End If

    If Form3.Label1.Visible = False Then
        Form3.Label1.Visible = True
    Else
        Form3.Label1.Visible = False
    End If

    If Form4.Label1.Visible = False Then
        Form4.Label1.Visible = True
    Else
        Form4.Label1.Visible = False
    End If
End Sub

End Class

这是我的问题。当我只打开表单1和2并单击按钮时,标签切换正常。但是,当我到达第三个(和第四个)窗口时,表格1和表格2上的标签将切换而不是第三个和第四个。另外,当我关闭第四个窗口时,它也会同时关闭第三个窗口。

我确定我在这里缺少一些东西。谢谢你的帮助。

0 个答案:

没有答案