Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (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 by JumpyNET
Posted

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

Posted

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.

~Nate�

___________________________________________

Please use the [vb]/[cs] tags on posted code.

Please post solutions you find somewhere else.

Follow me on Twitter here.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...