Click here to Skip to main content
15,880,392 members
Articles / .NET
Tip/Trick

ErrorMessageBox: an improved MessageBox for error reports

Rate me:
Please Sign up or sign in to vote.
4.81/5 (11 votes)
28 Jul 2013CPOL1 min read 9.4K   213   6   3
The MessageBox class works, but...why is it in the middle of the screen? Why does it expand to stupid sizes? Why can't the user copy and paste from it? So, I brewed my own.

Introduction   

MessageBox works: It's easy to use, it lets the user interact with us and make a decision, and it's not that ugly. But, for error messages (which is what I use it for most) it's not very helpful:

  • It always appears in the center of the screen. Normally, my dialogs appear in the middle of their parent, because that is where the users attention is focussed.  Hunting it down (or even noticing it is there at all) wastes user time, and looks unprofessional. 
  • It doesn't help much when you have a lot of info to transfer: it grows to fit the content, so you can end up with a dialog several times the size of your screen...and you can't tell in your code. 
  • The user can't highlight any text: so if you have six files you can't update, or a complex error message, he has to write it all down by hand - which means the error report he emails looks nothing like the error message you gave him. 

Using the code

So, I created a simple little ErrorMessageBox class - you use it the same way as you would a MessageBox - it includes all the necessary Show method overloads except for the handle based ones. I never use those anyway - please feel free to add them if you need them and let me know.  I'll include them in a future release and credit you.

The download includes both the class and a test application, which it is pretty obvious how to use. 

C#
DialogResult result = ErrorMessageBox.Show("There was a problem with this Update:\n" +
                                           "  The date is not recognisable \"2013-77-12\"",
                                           "I pressed the error button",
                                           MessageBoxButtons.OkCancel,
                                           MessageBoxIcons.Stop);

  

Or 

C#
DialogResult result = ErrorMessageBox.Show("Files not found:\n" + string.Join("\n", filesList),
                                           "I pressed the error button",
                                           MessageBoxButtons.OkCancel);

Or even simpler:

C#"
ErrorMessageBox.Show("HELP!");

History 

Original version.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
CEO
Wales Wales
Born at an early age, he grew older. At the same time, his hair grew longer, and was tied up behind his head.
Has problems spelling the word "the".
Invented the portable cat-flap.
Currently, has not died yet. Or has he?

Comments and Discussions

 
Questionimproved MessageBox for error reports Pin
Kushan Randima28-Aug-14 23:26
Kushan Randima28-Aug-14 23:26 
QuestionThank you Pin
Manikandan101-Jun-14 4:00
professionalManikandan101-Jun-14 4:00 
GeneralMy vote of 5 Pin
DaveyM6922-Jan-14 23:00
professionalDaveyM6922-Jan-14 23:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.