C # DialogBox and DialogResult

I want to get the DialogBox button that the user clicked ... but when I use DialogResult I get this error

'System.Windows.Window.DialogResult' is a 'property' but is used like a 'type'

How can I use DialogResult ??

Well, I managed to solve it.

MessageBoxResult Result = MessageBox.Show("Message Body", @"Caption/Title", MessageBoxButton.YesNo);
        switch (Result)
        {
            case MessageBoxResult.Yes:
                MessageBox.Show("Yes Pressed!!");
                break;
            case MessageBoxResult.No:
                MessageBox.Show("No Pressed!!");
                break;
        }
+5
source share
6 answers

Update: I just realized that you are using WPF, not WinForms. Here is the correct implementation of DialogResult in WPF:

MyDialog dialog = new MyDialog();
bool? dialogResult = dialog.ShowDialog();
if (dialogResult.HasValue && dialogResult.Value)
{
   // User clicked OK
}
else
{
   // User clicked Cancel"
}

There is a good tutorial here .

It looks like you are using the DialogResult property incorrectly . You should do something like the following:

DialogResult result = Form.DialogResult;
if (result == DialogResult.Yes)
{
   // Do something
}

You can find the full DialogResultlist of listings here .

+3
source

DialogBox? MessageBox ?

 DialogResult dlg = MessageBox.Show("Question User?",
                   "MessageBox Title",
                   MessageBoxButtons.YesNo,
                   MessageBoxIcon.Question);
            if (dlg == DialogResult.No)
            {
                //user changed mind. return
                return;
            }

.

+1

DialogResult - Enum - DialogResult .

0

If you are using WPF or Silverlight, is DialogResult a bool? and can you use ?? to supply a value if the result is zero.

if (myWindow.DialogResult ?? false)
    Debug.WriteLine("You clicked OK");
else
    Debug.WriteLine("You clicked Cancel");
0
source

You are using the WPF property DialogResult, which is Nullable<bool>, not an enumeration.

You need to check the result as follows:

bool? dialogResult = dialogBox.ShowDialog();

if (dialogResult.HasValue) // Should always have a value, at this point, since the dialogBox.ShowDialog() returned at this point.  Will be false until the dialog is closed, however
{
    if (dialogResult.Value)
    {
        // User "accepted" the dialog, hitting yes, OK, etc...
    }
    else
    {
        // User hit "cancel" button
    }
}
0
source

C # DialogBox and DialogResult

    {

        DialogResult a1 = MessageBox.Show("Test", "Title", MessageBoxButtons.YesNo);
        if (a1 == DialogResult.Yes)
            MessageBox.Show("Yes");
        else if (a1 == DialogResult.No)
            MessageBox.Show("No");

    }
0
source

All Articles