event handler for form closing in c#

Status
Not open for further replies.

john1a98

Newbie level 3
Joined
Oct 27, 2013
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Visit site
Activity points
18
Hi,

I am new to c#. I am writing code to event handler when windowsform is closed

My code:

Code:
private void CANToolFormClosing(object sender, CancelEventArgs e)
        {
            DialogResult dr = MessageBox.Show("Do you want to exit from the application?", "Are you Sure???", MessageBoxButtons.YesNo, MessageBoxIcon.Question);


            if (dr == DialogResult.No)
                e.Cancel = true;
        }

I do not understand why this code is not working.

Thanks in advance
John
 

What should happen?


Code - [expand]
1
2
3
4
5
6
7
8
private void button1_Click(object sender, EventArgs e)
{
            DialogResult dr = MessageBox.Show("Do you want to exit from the application?", "Are you Sure???", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
 
            if (dr == DialogResult.Yes)
                this.Close();
                        
}

 
Last edited:

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…