Click here to Skip to main content
13,299,727 members (67,894 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


6 bookmarked
Posted 28 Jul 2013

ErrorMessageBox: an improved MessageBox for error reports

, 28 Jul 2013
Rate this:
Please Sign up or sign in to vote.
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.


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. 

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",



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

Or even simpler:



Original version.


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


About the Author

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?

You may also be interested in...

Comments and Discussions

Questionimproved MessageBox for error reports Pin
Kushan Randima29-Aug-14 0:26
memberKushan Randima29-Aug-14 0:26 
QuestionThank you Pin
Manikandan101-Jun-14 5:00
professionalManikandan101-Jun-14 5:00 
GeneralMy vote of 5 Pin
DaveyM6923-Jan-14 0:00
mentorDaveyM6923-Jan-14 0: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.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.171207.1 | Last Updated 28 Jul 2013
Article Copyright 2013 by OriginalGriff
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid