Answered by:
close MessageboxResul is NO how can I stop the process to close

Question
-
Hello,
How can I stop the process to close the window after a messagebox asking if the do want to close? and they answer no.
Thanks
Wednesday, May 9, 2012 1:34 PM
Answers
-
You have probably used the Closed event of the window instead of Closing. If you look at my example you'll see it has a CancelEventArgs while you're error shows EventArgs instead.
- Marked as answer by SunnyShiny06 Wednesday, May 9, 2012 2:50 PM
Wednesday, May 9, 2012 2:49 PM
All replies
-
Add a handler for the Closing event of the window and set the Cancel property of CancelEventArgs to true to prevent closing the window:
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) { if (MessageBox.Show(this, "Are you sure?", Title, MessageBoxButton.YesNo) != MessageBoxResult.Yes) e.Cancel = true; }
- Marked as answer by SunnyShiny06 Wednesday, May 9, 2012 1:52 PM
- Unmarked as answer by SunnyShiny06 Wednesday, May 9, 2012 2:46 PM
Wednesday, May 9, 2012 1:47 PM -
Sorry it doesnt work to me.
Error 2 'System.EventArgs' does not contain a definition for 'Cancel' and no extension method 'Cancel' accepting a first argument of type 'System.EventArgs' could be found (are you missing a using directive or an assembly reference?) C
- Edited by SunnyShiny06 Wednesday, May 9, 2012 2:47 PM
Wednesday, May 9, 2012 2:46 PM -
You have probably used the Closed event of the window instead of Closing. If you look at my example you'll see it has a CancelEventArgs while you're error shows EventArgs instead.
- Marked as answer by SunnyShiny06 Wednesday, May 9, 2012 2:50 PM
Wednesday, May 9, 2012 2:49 PM -
Great man!
Thanks
Wednesday, May 9, 2012 2:51 PM