[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 407
  • Last Modified:

switching forms in winforms app

This should be a simple question.. I have a winform app with 2 forms. How do I switch between the two?
0
jayrod
Asked:
jayrod
1 Solution
 
cyberdevil67Commented:
using code

form1.Hide()

form2.Show()

0
 
YurichCommented:
i'd say it's rather a bit too simplified answer... what if he wants to switch forth and back, or just to switch from form2 to form1??

i suggest that one form is the main form and another one is the one you added,

presuming that you have a button "button1" to swtich your forms on the form1, add the following code to your main form:

Form2 f2 = null;
private void button1_Click(object sender, System.EventArgs e)
{
      if( f2 == null )
      {
            f2 = new Form2();
            f2.Owner = this;
      }
      this.Hide();
      f2.Show();
}

and again, having a button1 on the second form, add this code to your second form:

private void button1_Click(object sender, System.EventArgs e)
{
      this.Hide();
      (( Form )Owner ).Show();      
}


0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now