JackyBoi
JackyBoi

Reputation: 2773

Access to Message box buttons

I am having a message box a simple one inside an if condition and the thing is i want the message box to automatically close when the user points to the OK button in the message box, what i am not able to figure out is how to access the message box OK button

private void button3_Click(object sender, RoutedEventArgs e)
{
    Clipboard.Clear();

    //string queryvalue;
    //queryvalue = SelectedQuery.Value;
    //SelectedQuery.Value = queryvalue;
    if (QueryChooser.SelectedItem == null)
    {
        button3.Background = Brushes.PaleVioletRed;
        MessageBox.Show("Select a value");
    }
    else
    {
        Clipboard.SetText(SelectedQuery.Value);
    }
}

Upvotes: 0

Views: 202

Answers (2)

Robar
Robar

Reputation: 1971

if (MessageBox.Show("Select a value") == DialogResult.Ok) {
    // do something
}

UPDATE

As Saeb already mentioned you should create your own simple MessageBox dialog.

Upvotes: 1

Saeb Amini
Saeb Amini

Reputation: 24410

In cases like this I've found that it is easier to just create a simple Window resembling a MessageBox and pop it using ShowDialog(), this way you'll have a more flexible "MessageBox".

Upvotes: 3

Related Questions