C# DialogBox and DialogResult

cvisual studio 2010

I want to get the button of the DialogBox that the user clicked … yet when I use the DialogResult I get this error

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

How can I use the DialogResult??

Ok, I`ve 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;
        }

Best Answer

Update: Just realised you're using WPF, not WinForms. Here's a correct implementation of DialogResult within WPF:

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

There's a good tutorial on it here.

Just sounds like you're using the Form's DialogResult property incorrectly. You should be doing something like the following:

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

You can find the full DialogResult enumeration breakdown here.