I'm a little confused as to how I'm supposed to handle a chain of dialogs in my VB.net application. For example I have 4 forms, each one has a simple label and is subsequently called from the previous one as a dialog.
First form:
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
Second form:
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
Third form:
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
Fourth form:
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
And the class they all refer to just toggles the visibility of a label on each form:
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
Here's my question. When I only have forms 1 and 2 open and I click the button, the label toggle works fine. However, when I get to the third (and fourth) windows only the labels on form 1 and form 2 will toggle and not the third and fourth ones. Additionally, when I close the fourth window it also closes the third at the same time.
I'm sure there's something I'm missing here. Thanks for any help.