How to show a custom error or warning message box in .NET Winforms?

Viewed 394103

How can I show message boxes with a "Ding!" sound and a red 'close' button in it? This is what I'm talking about:

screenshot

I'm trying to create some custom errors and warnings, but this:

MessageBox.Show("asdf");

doesn't seem to give me any customization options.

4 Answers

Try this:

MessageBox.Show("Some text", "Some title", 
    MessageBoxButtons.OK, MessageBoxIcon.Error);

You should add namespace if you are not using it:

System.Windows.Forms.MessageBox.Show("Some text", "Some title", 
    System.Windows.Forms.MessageBoxButtons.OK, 
    System.Windows.Forms.MessageBoxIcon.Error);

Alternatively, you can add at the begining of your file:

using System.Windows.Forms

and then use (as stated in previous answers):

MessageBox.Show("Some text", "Some title", 
    MessageBoxButtons.OK, MessageBoxIcon.Error);
Related