Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / August 2006

Tip: Looking for answers? Try searching our database.

C# form close problem

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jason Huang - 18 Aug 2006 06:28 GMT
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
Morten Wennevik - 18 Aug 2006 06:50 GMT
Hi Jason,

You are probably better off having formA and formB share a common parent  
responsible for the message loop.
If formA is started from Main, have Main start both forms.  Pass  
properties to formB via Main.

What are you trying to do?

> Hi,
>
[quoted text clipped - 4 lines]
>
> Jason

Signature

Happy Coding!
Morten Wennevik [C# MVP]

Nand Kishore Gupta - 18 Aug 2006 07:14 GMT
You can do so using Show and Close method of the Form. Let us suppose that
you have 3 forms, Form1 (the main form), Form2 and Form3.

From Form2, if you want to open Form3 and close Form2, you can use the
following code:

Form3 f3 = new Form3();
f3.Show();   // Opens the Form3

this.Close(); // Closes the current form (Form2)

If you close Form1 (which might be the main form), the entire application
will close.

Signature

Nand Kishore Gupta

> Hi,
>
[quoted text clipped - 3 lines]
>
> Jason
Morten Wennevik - 18 Aug 2006 07:47 GMT
> You can do so using Show and Close method of the Form. Let us suppose  
> that
[quoted text clipped - 10 lines]
> If you close Form1 (which might be the main form), the entire application
> will close.

Not if you fire up another Form in your Main method

Application.Run(new Form1());
Application.Run(new Form2()); // will start when Form1 ends

Signature

Happy Coding!
Morten Wennevik [C# MVP]

WhiteWizard - 18 Aug 2006 13:47 GMT
Not sure you want to create two forms in one application that way, I'm pretty
sure you end up on two different threads.

You can also start the application without tying it to a particular form

Form1 frm1 = new Form1();
frm1.Show();
Application.Run();

Then you can open and or close forms without the problem of shutting down
the application when you close a form, or having to leave a form in memory
while your app is running even if you don't need it.

Of course it DOES introduce the problem of your having to specifically end
your application.

WhiteWizard
aka Gandalf
MCSD.NET, MCAD, MCT

> > You can do so using Show and Close method of the Form. Let us suppose  
> > that
[quoted text clipped - 15 lines]
> Application.Run(new Form1());
> Application.Run(new Form2()); // will start when Form1 ends

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.