JumpyNET Posted January 28, 2006 Posted January 28, 2006 (edited) I've always had to do this differently in every version of VB. So could someone please tell me what's the best practice in switching between two forms in the same application now in VB 2005? I tried the following, but the program crashes if I close one of the forms by clicking the red cross on the form's top right corner and then try to switch again. 'Switching to form2 from form1 Form2.Show() Form2.Select() 'Switching to form1 from form2 Form1.Show() Form1.Select() Could it be possible to cancel during unloading and hide the form instead? Edited January 29, 2006 by JumpyNET Quote
JumpyNET Posted January 29, 2006 Author Posted January 29, 2006 Problem solved!! OK, I found a way. :D I'll post the solution here incase I'm not the only one with this problem. In form1: Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Form2.Show() Form2.Select() End Sub Private Sub Form1_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing e.Cancel = True Me.Hide() End Sub In form2: Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Form1.Show() Form1.Select() End Sub Private Sub Form2_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing e.Cancel = True Me.Hide() End Sub Quote
Nate Bross Posted January 29, 2006 Posted January 29, 2006 I usually figure out what form is the 'main' form, if you will and do the following on it. Dim myForm as New Form2 myForm.Show() A while back I was working on an IM client, and I used this methodology in addition to using a collection to keep track; worked very well. Quote ~Nate� ___________________________________________ Please use the [vb]/[cs] tags on posted code. Please post solutions you find somewhere else. Follow me on Twitter here.
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.