x BlueRobot Administrator Staff member Joined May 7, 2013 Posts 10,265 Location %systemroot% Aug 7, 2013 #1 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:
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:
AceInfinity Emeritus, Contributor Joined Feb 21, 2012 Posts 1,728 Location Canada Aug 7, 2013 #2 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:
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: