Click here to Skip to main content
11,488,877 members (79,159 online)
Click here to Skip to main content

Tagged as

ErrorMessageBox: an improved MessageBox for error reports

, 28 Jul 2013 CPOL 3K 138 5
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.

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. 

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 

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

Or even simpler:

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)

Share

About the Author

OriginalGriff
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?
Follow on   Google+

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    Rant Rant    Admin Admin   

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

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.150520.1 | Last Updated 28 Jul 2013
Article Copyright 2013 by OriginalGriff
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid