Connecting Tech Pros Worldwide Forums | Help | Site Map

Hide active form while moving to next form

Member
 
Join Date: Nov 2008
Location: Chennai, India
Posts: 100
#1: 2 Weeks Ago
Hi,

i am working with C sharp dot net application, where i have more forms,.
i have to move to next form at the same time i have to hide the the existing form. it works fine in VB.net but not coming in csharp.net.

Can any one help me how to hide the active form when i move to next form

Thanks in advance,

Magesh

tlhintoq's Avatar
Moderator
 
Join Date: Mar 2008
Location: Arizona, USA
Posts: 1,783
#2: 2 Weeks Ago

re: Hide active form while moving to next form


The methods .Hide() and .Show() are what you should be using.
Member
 
Join Date: Nov 2008
Location: Chennai, India
Posts: 100
#3: 2 Weeks Ago

re: Hide active form while moving to next form


I Tried using
Expand|Select|Wrap|Line Numbers
  1. form f1 = new form1()
  2. f1.hide();
  3. form2 f2 = new form2()
  4. f2.show();
  5.  
But second form came to screen, but first form is still alive..

Regards,
tlhintoq's Avatar
Moderator
 
Join Date: Mar 2008
Location: Arizona, USA
Posts: 1,783
#4: 2 Weeks Ago

re: Hide active form while moving to next form


I seriously doubt that your new instance of Form1 is visible since you have not yet shown it.

You do realize you could have many instances of Form1, right? My guess is that your application starts in an instance of Form1 and that it is that instance of Form1 you are seeing. Making a *new* Form1 is not going to let you hide the *old* Form1
insertAlias's Avatar
Forum Leader
 
Join Date: Apr 2008
Location: San Antonio, TX (USA)
Posts: 2,608
#5: 2 Weeks Ago

re: Hide active form while moving to next form


If you're on the currently active form, and you want a second form to show, you'll need to do something like this:
Expand|Select|Wrap|Line Numbers
  1. Form2 f2 = new Form2();
  2. this.Hide();
  3. f2.Show();
The problem with this, however, is getting your original form to show again later. You'll need some reference to it to bring it back.
tlhintoq's Avatar
Moderator
 
Join Date: Mar 2008
Location: Arizona, USA
Posts: 1,783
#6: 2 Weeks Ago

re: Hide active form while moving to next form


I generally think that Form1 or whatever is the form that Program.cs launches shouldn't show. This is where I tend to stick a lot of the thinking of a program, but not the face of it.

That way it is always available, and it knows all the other forms/classes. It can then open the form "UserMain", "UserConfig", "UserPreferences"
tlhintoq's Avatar
Moderator
 
Join Date: Mar 2008
Location: Arizona, USA
Posts: 1,783
#7: 2 Weeks Ago

re: Hide active form while moving to next form


Alternatively, you can just make a reference to your Form1 in the Program.cs file.


Expand|Select|Wrap|Line Numbers
  1. public Form1 MyMainForm = new Form1();

Then launch MyMainForm as your interface.

From here forward any form can reach the main form through the program file.


Expand|Select|Wrap|Line Numbers
  1. Program.MyMainForm.Hide();
Reply


Similar C# / C Sharp bytes