Closing one form when going to the next

allyrnn

Member
Joined
Nov 22, 2004
Messages
5
Programming Experience
1-3
This is driving me crazy!! :eek: All i want to do is go from form1 to form2 and have form1 close in the process. I didn't think it would be this hard, it doesn't seem like a hard task. Is it? Any ideas?
 
Yes! you should put sb main in Module....

Also you may use a global Reference to the Form2. and can use form2 from that reference after the form1 is closed.
 
allyrnn said:
This is driving me crazy!! :eek: All i want to do is go from form1 to form2 and have form1 close in the process. I didn't think it would be this hard, it doesn't seem like a hard task. Is it? Any ideas?
try this one.
set form2 as startup object.
VB.NET:
 Dim frm2 As Form2
 	Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
 		frm2 = Me.Owner
 	End Sub
  Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
 		frm2.flag = True
 		Close()
 	End Sub
 --------------------------------
 
 Public flag As Boolean = False
 	Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
 		Dim frm1 As New Form1()
 		Me.AddOwnedForm(frm1)
 		frm1.ShowDialog()
 		If flag = False Then
 			Application.DoEvents()
 		End If
 	End Sub
 
Back
Top