Introduction
Every developer is familiar with the Windows MessageBox
, but sometimes we need just a little bit more. For instance, what if I want a "Don't show this warning again" checkbox at the bottom of my MessageBox
es, enabling the user to turn off certain alerts, but I don't want to write my own dialog from scratch, covering every possible button combination? The MsgBoxCheck
class does just that.
Background
This article, and the MsgBoxCheck
class, is built on two columns by Dino Esposito which appeared in MSDN Magazine's "Cutting Edge" in October and November of 2002. These describe the use of Windows Hooks in C#, in particular how to hook the creation and activation of the Windows MessageBox
.
Using the code
Using the MsgBoxCheck
class is as simple as using the Windows MessageBox
. First, add a reference to MsgBoxCheck.dll in your C# project. Most people will invoke the class as follows:
MsgBoxCheck.MessageBox dlg = new MsgBoxCheck.MessageBox();
DialogResult dr =
dlg.Show(@"Software\PricklySoft\TestMsgBoxCheck",
"DontShowAgain",DialogResult.OK,
"Don't ask me this again",
"Now is the time for all good men to check this message box",
"Hello",
MessageBoxButtons.OK, MessageBoxIcon.Information);
The first two parameters describe the registry key, and value name used to store a boolean variable which determines if the user does not want this message box shown. The third parameter is the default return value, which will be returned immediately if the message box is not shown. Next is the text for the check box, then the message box text itself, the title, button code, and icon code.