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.
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?