943,944 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Marked Solved
  • Views: 548
  • VB.NET RSS
Oct 23rd, 2009
0

Switching Between Forms

Expand Post »
I want to use more than one form in my project and be able to code a button or something that will do that. I tried this on Form1 and it worked.

VB.NET Syntax (Toggle Plain Text)
  1. Public Class Form1
  2.  
  3. Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
  4. 'Goes from this form to form 2
  5. My.Forms.Form2.Show()
  6. End Sub
  7.  
  8. End Class

BUT then I tried the following on Form2 to go back to Form1 and it doesn't work... the button does nothing.

VB.NET Syntax (Toggle Plain Text)
  1. Public Class Form2
  2.  
  3. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  4. My.Forms.Form1.Show() 'Doesn't work
  5.  
  6. End Sub
  7. End Class
Also, when the user switches to a different form, will the variables assigned on the first form still be assigned on the second form (assuming they're declared as Public in the module?
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
OldQBasicer is offline Offline
38 posts
since Oct 2009
Oct 24th, 2009
0
Re: Switching Between Forms
Form1
Button Event
Me.Hide
Form2.Show


Form2
Button Event
Me.Hide
Form1.Show
Last edited by yorro; Oct 24th, 2009 at 5:33 am.
Reputation Points: 8
Solved Threads: 7
Junior Poster
yorro is offline Offline
119 posts
since Aug 2009
Oct 24th, 2009
0
Re: Switching Between Forms
Got it. Thanks.
Reputation Points: 10
Solved Threads: 0
Light Poster
OldQBasicer is offline Offline
38 posts
since Oct 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: Need Help Save Settings
Next Thread in VB.NET Forum Timeline: Having a problem with datagrid view and combobox





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC