473,480 Members | 2,277 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

how to close one form and show another form

82 New Member
hello
i am working in C#.net. I want to know how to close one form and show another one. I had done the following code
Expand|Select|Wrap|Line Numbers
  1.                 this.Hide();
  2.                 MainForm frm = new MainForm();
  3.                 frm.Show();
  4.                 frm.Focus();
  5.                 frm.Activate();
  6.  
but when i close the last form activated then still it shows that the application is running. how can i completly close the first form
Mar 11 '08 #1
3 2380
spacemanafrica
6 New Member
One application can have multiple forms and it looks like that's what you're doing. Is that true? If so, the same executable will show up in the Task Manager for both forms.

-S.
Mar 11 '08 #2
dip_developer
648 Recognized Expert Contributor
hello
i am working in C#.net. I want to know how to close one form and show another one. I had done the following code
Expand|Select|Wrap|Line Numbers
  1. this.Hide();
  2. MainForm frm = new MainForm();
  3. frm.Show();
  4. frm.Focus();
  5. frm.Activate();
  6.  
but when i close the last form activated then still it shows that the application is running. how can i completly close the first form
suppose you want to close Form1 and show Form2 ...then in the Form_Closing event of Form1 write the following code...

Expand|Select|Wrap|Line Numbers
  1.  
  2. Form2 frm2;
  3. private void Form1_Closing(object sender, System.EventArgs e) 
  4. frm2 = new Form2(); 
  5. frm2.Show(); 
  6.  
Mar 11 '08 #3
agarwalsunitadhn
82 New Member
suppose you want to close Form1 and show Form2 ...then in the Form_Closing event of Form1 write the following code...

Expand|Select|Wrap|Line Numbers
  1.  
  2. Form2 frm2;
  3. private void Form1_Closing(object sender, System.EventArgs e) 
  4. frm2 = new Form2(); 
  5. frm2.Show(); 
  6.  
I had done the code provided by you bt it has the same problem as i previously written. what I done is that i call the Form1_Closing event from a button's click event. It shows both the form and application doesnt stop running. But when i close the newly created form i.e. Form2 then it will wait for the first one to close for termination of Application and when i click the first one form i.e. Form1 then the whole application terminate
Mar 12 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

5
9052
by: Viper | last post by:
.... say, like MS Word opens another instance of himself when you open another document. If you close the first 'Word', the second document remains alive. I can't figure out how to do the same...
6
1783
by: Ashish | last post by:
It might be basics for many but I never gave attention on this before. Steps: Add 2 forms (Form1/Form2) in application. Create a object in Form1 for Form2. Form2 f2 = new Form2(); //line...
1
5476
by: Alpha | last post by:
I have a Window based application that shows up still running in the task manager when I close it. It reaches the "this.close" statement and then it stops at the "}" at the section of the...
7
2502
by: Alice | last post by:
Hi, In my program, the user can navigate to many different forms. When they go to the next form, I want the form they have left to close. However, the forms aren't closing. Can anyone tell me...
6
6637
by: Tom | last post by:
Is there ANY easy way to close a MDI Child form in the middle of it's load? For instance, during the Load event I find a need to close the form (for whatever reason - maybe the user isn't ready for...
1
1472
by: Adam Honek | last post by:
Why oh why has MS changed so much in VB.NET I can't even figure out how to show/close a form as formname.show() doesnt work and the following doesn't either: formname.activeform.close() (or...
3
5893
by: Karan | last post by:
I am calling finalize when form2 loads and deactivates form1 which closes form1. However, same thing is not happening in form2 because finalize is already called. Does anybody has solution to it....
4
25560
by: Jason Huang | last post by:
Hi, In my C# windows form project, how do I in a formA open another formB, and close formA when formB is opened? Thanks for help. Jason
3
10642
by: Ronald S. Cook | last post by:
I know how to close and open a form... Well.. but can you tell me how can I do this..... Example... There are 2 forms...named formA and formB and each of them have their own button named...
3
2454
by: rajashekar4dotnet | last post by:
how to open one form from the other form and close the first form if there are only two forms in windows application(VB.net) i had tried this method dim f as new form2 form2.show( )...
0
7048
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6911
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7050
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7091
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6743
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5344
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4488
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
2999
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
2988
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.