Click here to Skip to main content
14,668,708 members
Rate this:
Please Sign up or sign in to vote.
I want to do when i close window form then ask
MessageBox.Show("Are You Sure You Want To Exit", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning)

how to do it using Dispose method in designer.cs form
help me
Posted
Updated 16-Jul-12 18:50pm
v3
Comments
Trak4Net 16-Jul-12 0:05am
   
Does it need to be in the Dispose method or would it be fine to use it in the form_closing event?

Rate this:
Please Sign up or sign in to vote.

Solution 3

You should use the FormClosing event instead. Here is a simple implementation that achieves what you need:
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
  if (MessageBox.Show("Are you sure you want to close the form?", "Warning", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.No)
  {
            e.Cancel = true;
  }
}
   
Rate this:
Please Sign up or sign in to vote.

Solution 2

This is how I typically handle it in the form_closing event. Not sure how you would handle it in dispose method since you won't know if user is closing or if system is logging off etc.

private void Form1_FormClosing(object sender, FormClosingEventArgs e)
       {
           if (e.CloseReason == CloseReason.UserClosing)
           {
              if (MessageBox.Show("Are You Sure You Want To Exit", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == System.Windows.Forms.DialogResult.No)
              {
                e.Cancel = true;
              }
           }
           else
           {
               if (handler != null) handler.Stop(); //my background thread processing class
           }
       }
   
v2
Rate this:
Please Sign up or sign in to vote.

Solution 1

this function must be returning some value...
catch it in a variable see it's content. Like Yes and now have specific numbers assgned to them , they are also referenced using vbYes and vbNo
if(var = vbYes) then
End 'Exit that is...
End if
   
Comments
kuldeepkumartak 15-Jul-12 23:42pm
   
where is set this function?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month



CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100