Employers - Post Free Jobs
Forum guidelines
AuthorQuestion
close 'X' button event question
Posted on: 24 May 2005
Hello, Can someone tell me what event is fired when the user clicks the 'X' button on the controlbox? For some reason the form will not close on any of my child forms when the user clicks this button. However, the parent form close 'X' button works just fine. Any ideas? Thanks
AuthorReply
Re: close 'X' button event question
Posted on: 26 May 2005  
If implemented, it will first fire the FormClosing event. If the eventargs.Cancel method is not executed there, then it will go on to close and fire the FormClosed event. As for closing the child forms, how do you create them? I have a project with two forms. The first form has a button that creates 5 instances of the second form. private void button1_Click(object sender, EventArgs e) { for (int j = 0; j < 5; j++) { Form2 frm = new Form2(); frm.Owner = this; frm.Show(); } } If I close the main form, the 5 children are destroyed and the application terminates. If I remove this line: frmOwner= this; ... then the children will not be destroyed when I close the main form and the application continues to run. Check the owner property of your child forms. If they are not owned, they will not be destroyed automatically.
doug
  • 0
  • 0
Re: close 'X' button event question
Posted on: 26 May 2005  
Thank you for your reply. I am currently not setting the Owner propery, but good to know. A couple of observations: 1.I am using the ShowDialog() method as opposed to the Show() method because I want them to do something in the form or destroy it. 2.The maximize and minimize buttons work fine no problem with them. 3.I am using serial communications very heavily and all of the forms are in while loops for getting data out of serial port (RS232). I created a very simple form fired from a button on the parent form. The close 'X' button worked until I added a while loop similar to the ones in my other child forms. I am using the App.DoEvents method in this loop to catch other events that are firing, but does not seem to work on the close button. Odd how it works with the min/max buttons. Wondering how that event would get killed just because of the while loop? Add this simple loop to one of your methods in the five forms you created and see if you have the same results. while(key_pressed !=0) //wait until user hit a key on the keyboard then go on Application.DoEvents(); //would think this would catch the close 'X' button
Re: close 'X' button event question
Posted on: 27 May 2005  
Well, Normally what i did for parent and child. Parent - .show() Child - .showdialog() So child definetely can close properly by calling this.Close() But to close parent, execute Application.Exit() Hope it helps :)

SPONSORED BY

Offshore Software and Database Development
MCN is your source for developing solutions involving websites, mobile apps, cloud-computing, databases, BI, back-end services and processes and client-server applications.