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

C#.NetWinforms

C# Problem Overview


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.

C# Solutions


Solution 1 - C#

Try this:

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

Solution 2 - C#

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

Solution 3 - C#

MessageBox.Show(
  "your message",
  "window title", 
  MessageBoxButtons.OK, 
  MessageBoxIcon.Asterisk //For Info Asterisk
  MessageBoxIcon.Exclamation //For triangle Warning 
)

Solution 4 - C#

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionclawsView Question on Stackoverflow
Solution 1 - C#Andrew HareView Answer on Stackoverflow
Solution 2 - C#Ahosan Karim AsikView Answer on Stackoverflow
Solution 3 - C#Onur AdıyamanView Answer on Stackoverflow
Solution 4 - C#TidesView Answer on Stackoverflow