prevent user closing the application

  • Thread starter Thread starter alan
  • Start date Start date
A

alan

Hello,

When the user try the close the application (click the top right side
button "X"), I would like to do a checking first. If the checking return
false, prevent the application terminate. Anyone know how to do it?
Thanks.
 
private void Form1_Closing(object sender,
System.ComponentModel.CancelEventArgs e)
{
if(some closing condition is not met)
{
e.Cancel = true;
}
}

Beware, this will also prevent windows from being able to close it when
you shut down your computer.
 
Oh! Is there nothing like a VB:
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)

Where 'UnloadMode' shows how the form is closing?

TIA
Krishnan
Codito Ergo Sum

private void Form1_Closing(object sender,
System.ComponentModel.CancelEventArgs e)
{
if(some closing condition is not met)
{
e.Cancel = true;
}
}

Beware, this will also prevent windows from being able to close it when
you shut down your computer.
 
Thanks Jeffrey, but the link doesn't seem to work.

Krishnan Codito Ergo Sum
 
Not sure, never used it as an email client, but I use it as a news
reader. It seems to do fine handling tens of thousands of mails in each
group. The line is sort of a default signature and I haven't changed it
yet.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top