Click here to Skip to main content
15,884,298 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hi !!!
Is it possible to hide a windows form after first use of it ? That form shuold not be appeared after first use.If yes, then how? Please someone give me help. I am developing a Windows based Application by using C# and SQL Server 2005.
Posted

You can if you call the forms Hide() method : http://www.techotopia.com/index.php/Hiding_and_Showing_Forms_in_C_Sharp[^]
 
Share this answer
 
Comments
Kishor Deshpande 10-Feb-13 10:50am    
My 5
Sergey Alexandrovich Kryukov 10-Feb-13 15:21pm    
Of course, a 5. I would only add: if the first form happens to be the main, the application still need to reserve a way to exit, say, by calling Application.Exit.
Without that, just closing of a main form would exit application (simply because it will exist Application.Run); with hidden main form, it won't work.
—SA
Please see my comment to Solution 1.

So, there is another technique which you could allow you to work with two different main form one by one. Let's say, you have two form classes; first one is your single-use form you wanted to hide after use forever, call if IntroductionForm, and another one is your "permanent" main form; call it MainForm.

C#
using System.Windows.Forms;

//...

        static void Main() {
            Application.Run(new IntruductionForm()); // during the use of this form, eventually close it instead of hiding
            // you won't need the instance of IntruductionForm, anyway, so it will be disposed; you won't be able to show it again,
            // but the resources it uses will be reclaimed, which is good
            Application.Run(new MainForm()); // since this point, everything goes in a usual way
        }

//...


It is important to understand that a form instance becomes a main form when it is used as an argument of Application.Run; unlike other forms, when a main form is closed, the method Application.Run returns.

This explains how it works.

—SA
 
Share this answer
 
v2
Comments
Mehdi Gholam 11-Feb-13 1:10am    
5'ed
Sergey Alexandrovich Kryukov 11-Feb-13 1:26am    
Thank you, Mehdi.
—SA
here is a sample example for you:
scenario: having two textboxes with a button opening a new form if values are correct

C#
Form2 f2 = new Form2();


       private void button1_Click(object sender, EventArgs e) // event of first forms button
       {

           if (textBox1.Text== "test" && textBox2.Text=="test")
           {

               f2.Show(); // will display new form
               this.Hide(); // hiding of current form
           }
           else
               MessageBox.Show("Entry not valid");
       }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900