473,598 Members | 2,916 Online
Bytes | Software Development & Data Engineering Community
+ 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 2396
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
9090
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 with mySecondForm.Show(); myFirstForm.Close(); // also closes mySecondForm too Thanks. A lot.
6
1789
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 //f2.Show(); // line 2 f2.Close(); // line 3
1
5488
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 following code after the "Application.Run(new VMSMain());": static void Main() { Application.Run(new VMSMain()); }
7
2513
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 what I'm doing wrong? Here is a sample snippet of code where the user can return to the main form while simultaneously closing the previous form.
6
6642
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 it yet, or it displays another form and they hit cancel). In any event, I need to be able to cause that MDI Child form to close. Just sticking Me.Close in there won't work, generates an error (note however, that on a NON-MDI form this seems to...
1
1487
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 show) doesn't seem to work but will compile. Thanks, Adam H.
3
5928
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. This code works well for splash screen. I searched alot on net for codes but they don't work. for example- (1) Public Sub CloseForm(formType As System.Type) For Each oForm as System.Windows.Forms.Form in me.MdiParent.MdiChildren If...
4
25572
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
10656
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 btnA and btnB The application starts with formA
3
2459
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( ) me.close( )
0
7981
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7894
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8284
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8392
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
6711
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
3938
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2410
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1500
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1245
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.