switching forms in winforms app

Posted on 2005-04-30
Last Modified: 2010-05-18
This should be a simple question.. I have a winform app with 2 forms. How do I switch between the two?
Question by:jayrod
    LVL 9

    Expert Comment

    using code



    LVL 21

    Accepted Solution

    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;

    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)
          (( Form )Owner ).Show();      


    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
    This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    754 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

    20 Experts available now in Live!

    Get 1:1 Help Now