Hide/Unhide C# form

Posted on 2005-05-17
Last Modified: 2008-07-26
I am new to C# so this is probably a very easy question.  I can't seem to figure it out though.  I have a form and when a certain button is clicked I want to hide the form and show a second form.  Then when the close button is clicked on the second form I want to unhide the first form.  

Here is my code for the first form showing the second form.
   fclsmynewform frmtest = new fclsmynewform();

How do I get my form to reappear without creating an instance of a new form?

Question by:tbailey922
    LVL 9

    Assisted Solution

    Well, there are a couple ways you could do it, I suppose.  You could pass a reference to the first form in the second form's constructor and then call Form1.Show() when you want it to reappear.  However, I would suggest creating an EventHandler for the second form's Closing event and do it there, instead.

    private void ShowForm2()
        Form2 f = new Form2();
        f.Closing += new CancelEventHandler(Form2_Closing);

    private void Form2_Closing(object sender, System.ComponentModel.CancelEventArgs e)
    LVL 1

    Accepted Solution


    In the button_Click event of Form1, place the following code:
    private void button2_Click_1(object sender, System.EventArgs e)
       Form2 frm2 = new Form2();
       this.Hide(); //Hides Form1

       frm2.ShowDialog(); //Displays Form2

       this.ShowDialog(); //After the form2 is closed, again displays Form1

    In Form2, place the following code in the Closing event:

    private void Form2_Closing(object sender, System.ComponentModel.CancelEventArgs e)

    Cheers !!

    Author Comment

    Thanks for the help!

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Join & Write a Comment

    Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
    Article by: Ivo
    Anonymous Types in C# by Ivo Stoykov Anonymous Types are useful when  we do not need to follow usual work-flow -- creating object of some type, assign some read-only values and then doing something with them. Instead we can encapsulate this read…
    This video discusses moving either the default database or any database to a new volume.
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    728 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