Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#2.0
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 10-Feb-13 5:42am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You can if you call the forms Hide() method : http://www.techotopia.com/index.php/Hiding_and_Showing_Forms_in_C_Sharp[^]
  Permalink  
Comments
Kishor Deshpande at 10-Feb-13 10:50am
   
My 5
Sergey Alexandrovich Kryukov at 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
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

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.
 
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
  Permalink  
v2
Comments
Mehdi Gholam at 11-Feb-13 1:10am
   
5'ed
Sergey Alexandrovich Kryukov at 11-Feb-13 1:26am
   
Thank you, Mehdi.
—SA
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

here is a sample example for you:
scenario: having two textboxes with a button opening a new form if values are correct
 
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");
       }
  Permalink  

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

  Print Answers RSS
0 BillWoodruff 330
1 Mathew Soji 309
2 Maciej Los 295
3 DamithSL 225
4 Afzaal Ahmad Zeeshan 217
0 OriginalGriff 6,369
1 Sergey Alexandrovich Kryukov 5,973
2 DamithSL 5,183
3 Manas Bhardwaj 4,673
4 Maciej Los 4,025


Advertise | Privacy | Mobile
Web04 | 2.8.1411019.1 | Last Updated 10 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100