Keeping MDI children alive
-
Howdy! I came across this new forum and realized that I still have a problem with a Windows Forms project I am toying with. I am creating a quicken like program. The main window creates a MDI child for each account (checking, credit card, and broker). I cannot figure out how to handle the close button. I want the form to just hide itself and remain in the main menu item that I dedicated to keeping the names of the children, so that the user can reselect and open the form again. However, this doesn't work:
private void CheckingAccountForm_FormClosing(object sender, FormClosingEventArgs e) { if (e.CloseReason == CloseReason.UserClosing) { this.Visible = false; } e.Cancel = true; }
The window is removed from the menu, and I currently have no way to bring it back. Ideally I would like to remove the close button from the header of the form but leave the other two. I can't see any way to get rid of that button without losing the others. I may just get rid of the header and add two custom buttons for the other two functions (minimize and full/screen toggle). Any ideas? Another pesky problem is that if I click the close button on the main form, it closes the children but stays open, and I gotta click the close buttong again. Thx. -
Howdy! I came across this new forum and realized that I still have a problem with a Windows Forms project I am toying with. I am creating a quicken like program. The main window creates a MDI child for each account (checking, credit card, and broker). I cannot figure out how to handle the close button. I want the form to just hide itself and remain in the main menu item that I dedicated to keeping the names of the children, so that the user can reselect and open the form again. However, this doesn't work:
private void CheckingAccountForm_FormClosing(object sender, FormClosingEventArgs e) { if (e.CloseReason == CloseReason.UserClosing) { this.Visible = false; } e.Cancel = true; }
The window is removed from the menu, and I currently have no way to bring it back. Ideally I would like to remove the close button from the header of the form but leave the other two. I can't see any way to get rid of that button without losing the others. I may just get rid of the header and add two custom buttons for the other two functions (minimize and full/screen toggle). Any ideas? Another pesky problem is that if I click the close button on the main form, it closes the children but stays open, and I gotta click the close buttong again. Thx.I don't know why You are defining The FormClosing method.. If You are using VC++ 2005 and you've placed a button on the form, that you want to close, all you have to do is setting up the Behavior property named DialogResult (you can choose the proper result's value from the checkbox placed on the right of the DialogResult property).. If user clicks the button, the form closes. The user can open it from main/parent form's menu again. In order to handle button's click you have to define
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {}
method, which you can choose with the button double clicking (in the design form) or with choosing it from the button's events. In abovementioned method's body you can also write code, like this :this->Close();
which will cause closing the form too (the form wich is the owner of the button). -
I don't know why You are defining The FormClosing method.. If You are using VC++ 2005 and you've placed a button on the form, that you want to close, all you have to do is setting up the Behavior property named DialogResult (you can choose the proper result's value from the checkbox placed on the right of the DialogResult property).. If user clicks the button, the form closes. The user can open it from main/parent form's menu again. In order to handle button's click you have to define
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {}
method, which you can choose with the button double clicking (in the design form) or with choosing it from the button's events. In abovementioned method's body you can also write code, like this :this->Close();
which will cause closing the form too (the form wich is the owner of the button).Thanks anyway, but that isn't it. I am talking about the red X button that you get in the right corner of any form you create where you do not set the ControlBox property to false.