| | |
close button event for form
Please support our C# advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jul 2009
Posts: 916
Reputation:
Solved Threads: 147
2
#2 29 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; 29 Days Ago at 10:37 am.
0
#4 28 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: 916
Reputation:
Solved Threads: 147
1
#5 27 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 ado.net algorithm array barchart bitmap box broadcast buttons c# check checkbox client color combobox control conversion csharp custom data database datagrid datagridview dataset datetime degrees development draganddrop drawing encryption enum event excel file finalyearproject form format forms function gdi+ getoutlookcontactusinfcsvfile globalization httpwebrequest image index input install installer java label list listbox mandelbrot math mono mouseclick mysql operator panel path photoshop picturebox pixelinversion post programming radians regex remote remoting richtextbox serialization server silverlight sleep socket sql sql-server statistics stream string table text textbox thread time timer timespan update upload usercontrol users validate validation visualstudio webbrowser windows winforms wpf xml





