Multiple Forms

Newbie_71

New member
Joined
Jun 22, 2005
Messages
3
Programming Experience
Beginner
Public Class Form1
Inherits ...

Private MiniForm As New Form2

Private Sub btnMiniForm_Click()
MiniForm.Visible = True
Me.Visible = False
End Sub

End Class

Public Class Form2
Inherits ...

Private Sub btnMainForm_Click
???
Me.Visible = False
End Sub

End Class

What can I do in the btnMainForm_Click procedure of Form2 to make Form1 (which Form2 is contained inside of) visible again?

Am I doing this all wrong? I only want one form open at a time.
 
How does any object affect any other object? You need to have a variable in Form2 that referes to Form1 in order to do anything to or with Form1. The logical thing to do would be to change the constructor of Form2 to take an argument of type Form1. That way, Form1 can pass a reference to itself, i.e. Me, to Form2 when it creates it. Form2 can then save that reference to a member variable which it can then use to access the specific instance of Form1 that created it any time it likes.

In Form2:
VB.NET:
Private myParent As Form1

Public Sub New(ByVal myParent As Form1)
    MyBase.New()
    InitializeComponent()

    Me.myParent = myParent
End Sub
In Form1:
VB.NET:
Private MiniForm As New Form2(Me)
 
Back
Top