Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF MessageBox Default To Cancel

Tags:

wpf

messagebox

With this the default is OK. Can I make the default Cancel?

   MessageBoxResult result = MessageBox.Show
      (message, caption, MessageBoxButton.OKCancel);
like image 686
paparazzo Avatar asked Aug 24 '11 17:08

paparazzo


People also ask

How to open a message box in WPF?

How to open a message box (WPF .NET) 1 Display a message box. To create a message box, you use the MessageBox class. ... The MessageBox.Show method overloads... 2 Handle a message box response. The MessageBox.Show method displays the message box and returns a result. ... When a... 3 See also. More ...

How to specify the default messagebox result?

Use this overload, which allows you to specify the default MessageBoxResult: MessageBoxResult result = MessageBox.Show (message, caption, MessageBoxButton.OKCancel, MessageBoxImage.Information, MessageBoxResult.Cancel);

How do I create a messagebox with OK and Cancel buttons?

By simply using MessageBoxButton.YesNo in the Show method, a MessageBox with OK and Cancel buttons is created. The following code snippet creates a MessageBox with a message, a title, and two OK and Cancel buttons: The output looks as in Figure 7.

What is a message box in Visual Studio?

A message box is a dialog box that is used to quickly display information and optionally allow users to make decisions. Access to the message box is provided by the MessageBox class. A message box is displayed modally.


1 Answers

Use this overload, which allows you to specify the default MessageBoxResult:

MessageBoxResult result = MessageBox.Show
    (message, caption, MessageBoxButton.OKCancel,  
        MessageBoxImage.Information, MessageBoxResult.Cancel);
like image 162
Robert Harvey Avatar answered Oct 19 '22 13:10

Robert Harvey