Possibly very simple question - How to jump between two forms

Posted on 2005-04-19
Last Modified: 2011-09-21

I've only recently begun playing around with Visual (I presume this is the place to ask this question, as I didn't see a section dedicated to this) and I have a (possibly) very simple question.

I've searched in google, and for the love of god, I just simply couldn't find how to jump between two forms using a command button.  I've only really had experience with VB, and abit of C++, but I just can't seem to find this answer.  All the tutorials that I could find seem to only use a single form, and mostly involve steps on how to put text boxes and what-not in, but none mentioned how to switch between forms.

Lets assume I have to forms:  Contacts and Suppliers.  Both forms have a command button that links to the other form.  What do I need to do, so that once pressed, a button opens the other form (and vis versa).

Question by:Sebastion

    Expert Comment


    Let say that the command button on the Contacts form is called btnSuppliers and that the suppliers form is called frmSuppliers.  This is what the code will look like.. (and vis versa)

    // from the Contacts form
    private void btnSuppliers_Click(object sender, System.EventArgs e)
          frmSuppliers gotoSuppliers = new frmSuppliers();

    // from the Suppliers form
    private void btnContacts_Click(object sender, System.EventArgs e)
          frmContacts gotoContacts = new frmContacts();

    LVL 21

    Accepted Solution

    i'm afraid it's not exactly right and i'm not sure it's going to work,
    since if I click 10 times on any of the button I'm going to have 10 instances of the very two classes?
    why would you want to create new instances including of your main form as well...

    few things are not clear - do you want to hide another form while you're working with one or it still can be sitting somewhere behind the first one?

    are they only two forms you have and is your first one, Contacts, your main form as well?

    let's presume you first form is your main form, you want to create your secondary form and then switch between them on will, view only the one your'r working with...

    1. Form1 and Form2, Form1 is the main form, Form2 is added form.
    Form1 has a button "Go to Form2", and Form2 has a button "Go to Form1"

    2. create an instance of your second form somewhere in the class scope of your first form (can do before the constructor):

    Form2 f2 = null;

    // and here your constructor will be...

    3. Add a button, name it whatever your want and double-click it to get to its click event, add the code and it should look like:

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

    4. add a button to your second form, double click it, add the code below, and your click_event should look like:

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

    that should work fine


    LVL 8

    Expert Comment

    You can declare a var for friend form.

          public class MyForm : System.Windows.Forms.Form
                private System.Windows.Forms.Button GoToFriend;
                public   System.Windows.Forms.Form MyFriend = null;
                private void GoToFriend_Click(object sender, System.EventArgs e)
          MyForm form1 = new MyForm();
          MyForm form2 = new MyForm();
          form1.MyFriend = form2;
          form2.MyFriend = form1;


    Good luck

    Author Comment

    Yurich, thanks for the help, that is what I meant.

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

    731 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now