[SOLVED] [C#] Form Doesn't Produce Message Box When Closing

x BlueRobot

Administrator
Staff member
Joined
May 7, 2013
Posts
10,400
Code:
 private void Form1_FormClosing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            if (MessageBox.Show("Do you want to exit?", "Test", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                e.Cancel = true;
            }
        }

When the red X is clicked by the user, a message box is meant to appear, asking if they wish to close the program. This message box doesn't seem to appear.

Any suggestions would be appreciated :)

EDIT:

Code:
public Form1()
        {
            InitializeComponent();

            this.FormClosing += Form1_FormClosing;
}

Added this Event Handler, and the program now works as it should do :dance:
 
It should've added itself to the designer if you double clicked on it's entry in the properties window, which is another way (instead of cluttering up your form's constructor). :beerchug2:
 

Has Sysnative Forums helped you? Please consider donating to help us support the site!

Back
Top