Click here to Skip to main content
15,867,330 members
Articles / Programming Languages / C#
Article

A "Don't show this again" checkbox for the .NET MessageBox

Rate me:
Please Sign up or sign in to vote.
3.95/5 (23 votes)
14 May 20041 min read 202.9K   3.5K   68   37
A C# class which uses Dino Esposito's LocalCbtHook component to add a "Don't show this again" checkbox to any .NET MessageBox.

Sample Image - MessageBoxChk.gif

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 MessageBoxes, 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:

C#
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.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
United States United States
Visit http://mike.pricklysoft.com

Comments and Discussions

 
Generalsource code Pin
stadelmann-peter17-Dec-08 6:32
stadelmann-peter17-Dec-08 6:32 
GeneralRe: source code Pin
donor23-Dec-08 4:52
donor23-Dec-08 4:52 
GeneralRe: source code Pin
Member 113944985-Jul-15 5:38
Member 113944985-Jul-15 5:38 
GeneralWhere do I find the MsgBoxCheck.dll file Pin
Glade Ross14-Jul-08 11:02
Glade Ross14-Jul-08 11:02 
GeneralRe: Where do I find the MsgBoxCheck.dll file Pin
Hantou30-Apr-09 10:40
Hantou30-Apr-09 10:40 
GeneralRe: Where do I find the MsgBoxCheck.dll file Pin
rg21k28-Apr-13 11:25
rg21k28-Apr-13 11:25 
GeneralParameter to set the default button please Pin
Taner Riffat19-Jun-08 3:16
Taner Riffat19-Jun-08 3:16 
QuestionVista Problem Pin
Turulo10-Apr-08 9:33
Turulo10-Apr-08 9:33 
AnswerRe: Vista Problem Pin
Taner Riffat19-Jun-08 3:11
Taner Riffat19-Jun-08 3:11 
GeneralLicense Attached Pin
rsbiz200426-Mar-08 1:07
rsbiz200426-Mar-08 1:07 
QuestionAnd in vbnet ? Pin
scalpa9822-Sep-07 8:31
scalpa9822-Sep-07 8:31 
Can you post this code in vb 2005 please for young learner ?
thank you

scalpa
http://www.scalpa.info

AnswerRe: And in vbnet ? Pin
rsbiz200424-Mar-08 2:44
rsbiz200424-Mar-08 2:44 
GeneralRe: And in vbnet ? Pin
BMarik21-Jan-14 10:34
BMarik21-Jan-14 10:34 
Questionhow to use this from a visual c++ sln? Pin
laura_glow13-Jun-07 10:06
laura_glow13-Jun-07 10:06 
Generalimplementation to HTML Pin
jameo186-Jun-07 3:48
jameo186-Jun-07 3:48 
GeneralMsgBoxCheck.dll source code or reg path Pin
wilsoada13-Dec-06 12:37
wilsoada13-Dec-06 12:37 
GeneralDon't like the use of registry Pin
Piotr Perak20-Oct-06 4:06
Piotr Perak20-Oct-06 4:06 
GeneralRe: Don't like the use of registry Pin
manisys24-Mar-08 12:31
manisys24-Mar-08 12:31 
GeneralSource Code Pin
MArrington6-Feb-06 3:23
MArrington6-Feb-06 3:23 
GeneralRe: Source Code Pin
Mike Scanlon9-Feb-06 8:09
Mike Scanlon9-Feb-06 8:09 
GeneralWorked ok for me in VB.NET Pin
Drogil20-Jul-05 15:33
Drogil20-Jul-05 15:33 
GeneralNot useful for me ... unless.. Pin
Member 191074625-May-05 6:00
Member 191074625-May-05 6:00 
GeneralRe: Not useful for me ... unless.. Pin
Angeliyo14-Jul-05 23:53
Angeliyo14-Jul-05 23:53 
GeneralRe: Not useful for me ... unless.. Pin
Blazetopher3-Jul-06 9:18
Blazetopher3-Jul-06 9:18 
Generaluseful Pin
sreejith ss nair2-Mar-05 18:09
sreejith ss nair2-Mar-05 18:09 

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.