Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Saturday, April 5, 2014 2:32 PM | 1 vote
I am developping my first application in visual studio 2013 using c# so i am a beginner. I got 2 forms. If i click the close button(X) on the first form the application will close so it's ok but if i click the X button on the second form it will only close the form, not the program. How i can modify the close event so it will do Application.Exit() instead of this.close(); ?
All replies (5)
Saturday, April 5, 2014 2:44 PM ✅Answered
Hi, you can handle Form.FormClosed event of the second form to call Application.Exit(). For example:
private void Form2_FormClosed(object sender, FormClosedEventArgs e)
{
Application.Exit();
}
About FormClosed event:
http://msdn.microsoft.com/en-us/library/system.windows.forms.form.formclosed.aspx
Saturday, April 5, 2014 3:27 PM ✅Answered | 2 votes
In the Form designer, go to the Properties window. There are icons on the top to switch your viewing to Events instead of Properties (sorry, I don't have VS 2013 available at the moment, so I can't describe the icons for you ...hover your mouse over the icons at the top of the Properties page and you'll see which icon it is).
Once you're looking at events, find the Closed event and double-click it. It will create the Form2_Closed event handler for you in your code. Then put the Application.Exit(); statement there as Iapheal suggested.
~~Bonnie DeWitt [C# MVP]
http://geek-goddess-bonnie.blogspot.com
Saturday, April 5, 2014 2:59 PM
And where i must incude the Form2_FormClosed method? And how? I am new to OOP.
Saturday, April 5, 2014 3:50 PM
Wow. So simple! I mean i tried like 1 hour to do this , looked everywhere and ... Thank you very much!
Saturday, April 5, 2014 3:59 PM
You're welcome! Glad I could help. =0) You should mark my reply and @lapheal's reply as answers.
~~Bonnie DeWitt [C# MVP]