106

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 4

296

Try this:

MessageBox.Show("Some text", "Some title", 
    MessageBoxButtons.OK, MessageBoxIcon.Error);
2
  • 8
    MSDN: Other icons you can use : msdn.microsoft.com/en-us/library/…
    – claws
    Jan 21, 2010 at 14:00
  • 3
    now it's not supported MessageBoxIcon.Error. try something like MessageBox.Show("Some text", "Some title", MessageBoxButton.OK,MessageBoxImage.Warning);
    – JPerk
    Apr 3, 2018 at 21:51
23

Try details: use any option:

MessageBox.Show(
    "your message",
    "window title", 
    MessageBoxButtons.OK, 
    MessageBoxIcon.Warning // for Warning  
    //MessageBoxIcon.Error // for Error 
    //MessageBoxIcon.Information  // for Information
    //MessageBoxIcon.Question // for Question
);
7
MessageBox.Show(
  "your message",
  "window title", 
  MessageBoxButtons.OK, 
  MessageBoxIcon.Asterisk //For Info Asterisk
  MessageBoxIcon.Exclamation //For triangle Warning 
)
2

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);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.