Click here to Skip to main content
11,495,049 members (36,363 online)
Click here to Skip to main content

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

, 14 May 2004 132.2K 2K 67
Rate this:
Please Sign up or sign in to vote.
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:

    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

Share

About the Author

Mike Scanlon
Web Developer
United States United States
Visit http://mike.pricklysoft.com

Comments and Discussions

 
QuestionMessage box only runs once even without checkbox checked Pin
BMarik21-Jan-14 6:19
memberBMarik21-Jan-14 6:19 
BugMy chkMessageBox has 2 colors? Pin
Member 1001584128-Apr-13 12:35
memberMember 1001584128-Apr-13 12:35 
GeneralRe: My chkMessageBox has 2 colors? Pin
Proshuto20-Jun-13 0:45
memberProshuto20-Jun-13 0:45 
GeneralRe: My chkMessageBox has 2 colors? Pin
Member 103232869-Oct-13 9:29
memberMember 103232869-Oct-13 9:29 
QuestionRe: My chkMessageBox has 2 colors? Pin
Johnny J.19-Sep-14 2:33
professionalJohnny J.19-Sep-14 2:33 
GeneralThere is a WinApi function what does it ! Pin
adata210-Feb-11 10:57
memberadata210-Feb-11 10:57 
GeneralRe: There is a WinApi function what does it ! Pin
hype891230-Nov-12 4:24
memberhype891230-Nov-12 4:24 
Generalrendering problems sometime Pin
Sergey Kolomenkin17-Mar-09 3:48
memberSergey Kolomenkin17-Mar-09 3:48 
Generalsource code Pin
stadelmann-peter17-Dec-08 7:32
memberstadelmann-peter17-Dec-08 7:32 
GeneralRe: source code Pin
donor23-Dec-08 5:52
memberdonor23-Dec-08 5:52 
GeneralWhere do I find the MsgBoxCheck.dll file Pin
Glade Ross14-Jul-08 12:02
memberGlade Ross14-Jul-08 12:02 
GeneralRe: Where do I find the MsgBoxCheck.dll file Pin
Hantou30-Apr-09 11:40
memberHantou30-Apr-09 11:40 
GeneralRe: Where do I find the MsgBoxCheck.dll file Pin
Member 1001584128-Apr-13 12:25
memberMember 1001584128-Apr-13 12:25 
GeneralParameter to set the default button please Pin
SuperCoder!19-Jun-08 4:16
memberSuperCoder!19-Jun-08 4:16 
QuestionVista Problem Pin
Turulo10-Apr-08 10:33
memberTurulo10-Apr-08 10:33 
AnswerRe: Vista Problem Pin
SuperCoder!19-Jun-08 4:11
memberSuperCoder!19-Jun-08 4:11 
GeneralLicense Attached Pin
rsbiz200426-Mar-08 2:07
memberrsbiz200426-Mar-08 2:07 
QuestionAnd in vbnet ? Pin
scalpa9822-Sep-07 9:31
memberscalpa9822-Sep-07 9:31 
AnswerRe: And in vbnet ? Pin
rsbiz200424-Mar-08 3:44
memberrsbiz200424-Mar-08 3:44 
GeneralRe: And in vbnet ? Pin
BMarik21-Jan-14 11:34
memberBMarik21-Jan-14 11:34 
Questionhow to use this from a visual c++ sln? Pin
laura_glow13-Jun-07 11:06
memberlaura_glow13-Jun-07 11:06 
Generalimplementation to HTML Pin
jameo186-Jun-07 4:48
memberjameo186-Jun-07 4:48 
GeneralMsgBoxCheck.dll source code or reg path Pin
wilsoada13-Dec-06 13:37
memberwilsoada13-Dec-06 13:37 
GeneralDon't like the use of registry Pin
Piotr Perak20-Oct-06 5:06
memberPiotr Perak20-Oct-06 5:06 
GeneralRe: Don't like the use of registry Pin
manisys24-Mar-08 13:31
membermanisys24-Mar-08 13:31 
GeneralSource Code Pin
MArrington6-Feb-06 4:23
memberMArrington6-Feb-06 4:23 
GeneralRe: Source Code Pin
Mike Scanlon9-Feb-06 9:09
memberMike Scanlon9-Feb-06 9:09 
GeneralWorked ok for me in VB.NET Pin
Drogil20-Jul-05 16:33
memberDrogil20-Jul-05 16:33 
GeneralNot useful for me ... unless.. Pin
Brett Swift25-May-05 7:00
memberBrett Swift25-May-05 7:00 
GeneralRe: Not useful for me ... unless.. Pin
Angeliyo15-Jul-05 0:53
memberAngeliyo15-Jul-05 0:53 
GeneralRe: Not useful for me ... unless.. Pin
Blazetopher3-Jul-06 10:18
memberBlazetopher3-Jul-06 10:18 
Generaluseful Pin
sreejith ss nair2-Mar-05 19:09
membersreejith ss nair2-Mar-05 19:09 
GeneralOne Thing I'd Like Pin
Dalan Galma16-Feb-05 15:34
memberDalan Galma16-Feb-05 15:34 
GeneralThis is easy to achieve Pin
konamiman3419-Nov-07 23:22
memberkonamiman3419-Nov-07 23:22 
GeneralGreat! Pin
Mach00519-May-04 21:32
memberMach00519-May-04 21:32 

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
Web02 | 2.8.150520.1 | Last Updated 15 May 2004
Article Copyright 2004 by Mike Scanlon
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid