Reputation: 11151
Working on development of C# application.
I want to keep Close button on top right in title bar, but if end users click on it, all I want is that he gets info window that he can not close application until some other proper button.
Is it possible to achieve?
Tnx in adv!
Upvotes: 0
Views: 641
Reputation: 30097
You can handle the FormClosing
event event handler like this
private void Form_FormClosing(object sender, FormClosingEventArgs e)
{
//there can be other reasons for form close make sure X button is clicked
// if close button clicked
if (e.CloseReason == CloseReason.UserClosing)
{
e.Cancel = true;
}
}
Upvotes: 3
Reputation: 36487
Add an event handler to the OnClosing
event of the form. The event argument contains an element Cancel
. Set it to true
and it won't close.
Essentially something like this:
private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
e.Cancel = !stuffdone;
}
Upvotes: 4