| | |
close button event for form
Please support our C# advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jul 2009
Posts: 901
Reputation:
Solved Threads: 142
2
#2 23 Days Ago
You can handle the close event on the form using the following event handler:
The above event will be called whenever the
C# Syntax (Toggle Plain Text)
private void Form1_FormClosing(object sender, FormClosingEventArgs e) { if (DialogResult.No == MessageBox.Show("Exit without saving changes?", "Data Not Saved", MessageBoxButtons.YesNo)) e.Cancel = true; }
The above event will be called whenever the
Close() method is executed. Use e.Cancel = true to stop the form from being closed. Last edited by DdoubleD; 23 Days Ago at 10:37 am.
0
#4 22 Days Ago
Double clicking on a control will create the default event handler. To create handles for other events, got to the properties panel and change to the Events section (lightning bolt at top).
Then double click on the area next to the required event and a basic event handler will be created for you.
Check out the image to see where you ened to click.
Remember to mark the thread as solved if this answered your question.
Then double click on the area next to the required event and a basic event handler will be created for you.
Check out the image to see where you ened to click.
Remember to mark the thread as solved if this answered your question.
Please don't take for granted the work that solvers do for you. Take the time to fully understand the code they give you so that you might adapt it to future problems.
"Learning is more than absorbing facts, it is acquiring understanding.” - William Arthur Ward
"Learning is more than absorbing facts, it is acquiring understanding.” - William Arthur Ward
•
•
Join Date: Jul 2009
Posts: 901
Reputation:
Solved Threads: 142
1
#5 21 Days Ago
You can also add the event handler directly in your form's constructor in the form of:
C# Syntax (Toggle Plain Text)
public Form1() { InitializeComponent(); this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Form1_FormClosing); }
![]() |
Similar Threads
- Disable the Close Button until the clicks on the LogOff button (C#)
- command object insert operation (Visual Basic 4 / 5 / 6)
- Making sure my button can only creat one Form at a time... (C#)
- Disable Close button on form (C++)
- Disable MDI child close button (ASP.NET)
- Browser Close Button (ASP.NET)
- Closed event of a form (C#)
Other Threads in the C# Forum
- Previous Thread: Returning an array of objects
- Next Thread: How to play Video?
| Thread Tools | Search this Thread |
.net access algorithm array asp.net barchart bitmap box broadcast c# check checkbox client combobox control conversion csharp custom database databaseconnection datagrid datagridview dataset datetime dbconnection degrees design development draganddrop drawing encryption enum event eventhandlers excel file firefox form format forms function gdi+ grantorrevokepermissionthroughc#.net httpwebrequest image index input install java label libraries list listbox loop mandelbrot marshalbyrefobject math mouseclick movingimage mysql mysql.data.client operator path photoshop picturebox pixelinversion post programming radians regex remote remoting resourcefile richtextbox server sleep socket sql statistics stream string study system.servicemodel table tcpclientchannel text textbox thread time timer update usercontrol validation visualstudio webbrowser windows winforms wpf wpfc# xml





