Tuesday 12 April 2016

MsgBox - A Better Winforms MessageBox in C#



Introduction

MsgBox is an enhanced solution to the in-built MessageBox class. It's designed so that the styles, features and behaviour mimic the in-built control with added features.
MsgBox allows a better Messagebox experience by allowing the following features:
- Do not display this message again
- Custom font styles and font colors
- Scrollbars for text which is too long

Using the code

MsgBox is used like a standard MessageBox object. There is a different return object which encapsulates the original DialogResult. This handles extra information which as whether the user clicked 'Do no display this message again'.

Simple Example
Code Snippet
  1. MsgBox.Show(this, "Hello", "Caption Text", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
End of Code Snippet



Custom Fonts
Code Snippet
  1. MsgBox.Show(this, "Hello", "Caption Text", MessageBoxButtons.OK, MessageBoxIcon.Information, true, new Font("Verdana", 12f, FontStyle.Bold), Color.Red);
End of Code Snippet



Long Text
Code Snippet
  1. MsgBox.Show(this, "Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello", "Caption Text", MessageBoxButtons.OK, MessageBoxIcon.Information, true, new Font("Verdana", 40f, FontStyle.Bold), Color.Blue);
End of Code Snippet



Handling the do not display message again checkbox
Code Snippet
  1. DialogResultNew res = MsgBox.Show(this, "Hello", "Caption Text", MessageBoxButtons.OK);
  2. if (res.DoNotDisplayMessageAgain) // Do something here
End of Code Snippet

Download


Download MsgBox Here

History

v1.0 - Initial write-up

No comments: