close winforms childs and main
-
Hi I have application that is define as MDI, there are several form child once the user press X button, i wish the application to be close and all other windows. at the FromClosing event i add the following code //handle and close the logic layer... foreach (Form frm in this.MdiChildren) { frm.Close(); frm.Dispose(); } Application.Exit(); All childs are closed but the the event FromClosing happen agian, why? i would expect the event of the main form FromClosing will happen only one time. this cause my problems at the logic layer ronen
-
Hi I have application that is define as MDI, there are several form child once the user press X button, i wish the application to be close and all other windows. at the FromClosing event i add the following code //handle and close the logic layer... foreach (Form frm in this.MdiChildren) { frm.Close(); frm.Dispose(); } Application.Exit(); All childs are closed but the the event FromClosing happen agian, why? i would expect the event of the main form FromClosing will happen only one time. this cause my problems at the logic layer ronen
Ronenb wrote:
All childs are closed but the the event FromClosing
happen agian, why?Because you called "Application.Exit", which will close all the forms and exit the application. You needn't close all forms manually, exiting the application should be enough and should close all remaining forms (and dispose them) automagically.
Bastard Programmer from Hell :suss:
-
Ronenb wrote:
All childs are closed but the the event FromClosing
happen agian, why?Because you called "Application.Exit", which will close all the forms and exit the application. You needn't close all forms manually, exiting the application should be enough and should close all remaining forms (and dispose them) automagically.
Bastard Programmer from Hell :suss:
in case i will remove closing the child manully, once i click close "X", each time child window will be closed i need to press X button accurding the number of child windows that are opend what am i'm missing? what is the correct process to close MDI application? thanks ronen
-
in case i will remove closing the child manully, once i click close "X", each time child window will be closed i need to press X button accurding the number of child windows that are opend what am i'm missing? what is the correct process to close MDI application? thanks ronen
There are TWO X-es on a MDI-form if you have the children maximized. If you want to close the application, you close the mainform. That's how things work in Windows, and across all other MDI-applications. If you close one of the child-windows by using it's X, then you are merely closing that particular document of the "Multiple Document Interface". Likewise, Ctrl-F4 would close a child-document, Alt-F4 would close the application.
Ronenb wrote:
what is the correct process to close MDI application?
Application.Exit from code, the X topright of the mainform or Alt-F4 from user-input.
Bastard Programmer from Hell :suss:
-
There are TWO X-es on a MDI-form if you have the children maximized. If you want to close the application, you close the mainform. That's how things work in Windows, and across all other MDI-applications. If you close one of the child-windows by using it's X, then you are merely closing that particular document of the "Multiple Document Interface". Likewise, Ctrl-F4 would close a child-document, Alt-F4 would close the application.
Ronenb wrote:
what is the correct process to close MDI application?
Application.Exit from code, the X topright of the mainform or Alt-F4 from user-input.
Bastard Programmer from Hell :suss:
i'm trying to closing the app by the mainform X :), not the child form X the status is when i press the mainform X, a child win is closed, each click close child form till all childs are closed, last click on X close the app once no child exist any advice?
-
i'm trying to closing the app by the mainform X :), not the child form X the status is when i press the mainform X, a child win is closed, each click close child form till all childs are closed, last click on X close the app once no child exist any advice?
Ronenb wrote:
any advice?
Yes. Post the code from the children's OnCloseForm handler. Start a new project, add this code;
namespace WindowsFormsApplication15
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.IsMdiContainer = true;new Form() { MdiParent = this, Visible = true }; new Form() { MdiParent = this, Visible = true }; } }
}
That'll display two documents within a MDI-parent. App will close on X, unless you have some custom code somewhere.
Bastard Programmer from Hell :suss:
-
i'm trying to closing the app by the mainform X :), not the child form X the status is when i press the mainform X, a child win is closed, each click close child form till all childs are closed, last click on X close the app once no child exist any advice?
Do any of the child forms have FormClosing(..) handlers? If so check them to see if they might be doing anything that's interfering, such as setting e.Cancel to true. You might also try stepping through the main form's closing handler with the debugger if you haven't done that already.
BDF I often make very large prints from unexposed film, and every one of them turns out to be a picture of myself as I once dreamed I would be. -- BillWoodruff