this.Close() (form method)

wyrd

Senior Contributor
Joined
Aug 23, 2002
Messages
1,405
Location
California
Question..

Why does this.Close() exit and dispose the main application form, yet on newly created forms (Form frm = new Form();) the Close() method doesn't automatically dispose the form, only hides it?
 
The way .NET Windows Forms apps are initially set up, the program's message loop depends on the first form shown. Therefore, when it is closed there's no way the program can remain running any UI elements.

Application.Run() when called without any parameters sets up the message loop so it doesn't rely on any one form being open, but it does have the side effect that you have to terminate your message loop manually using Application.Exit() when all forms have been closed.
 
Back
Top