110

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.

TylerH
  • 20,799
  • 66
  • 75
  • 101
claws
  • 52,236
  • 58
  • 146
  • 195

4 Answers4

300

Try this:

MessageBox.Show("Some text", "Some title", 
    MessageBoxButtons.OK, MessageBoxIcon.Error);
caiosm1005
  • 1,686
  • 1
  • 19
  • 31
Andrew Hare
  • 344,730
  • 71
  • 640
  • 635
  • 8
    MSDN: Other icons you can use : http://msdn.microsoft.com/en-us/library/system.windows.forms.messageboxicon.aspx – claws Jan 21 '10 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 03 '18 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
);
TylerH
  • 20,799
  • 66
  • 75
  • 101
Ahosan Karim Asik
  • 3,219
  • 1
  • 18
  • 27
7
MessageBox.Show(
  "your message",
  "window title", 
  MessageBoxButtons.OK, 
  MessageBoxIcon.Asterisk //For Info Asterisk
  MessageBoxIcon.Exclamation //For triangle Warning 
)
Antonio
  • 19,451
  • 13
  • 99
  • 197
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);
Tides
  • 111
  • 11