Click here to Skip to main content
Licence 
First Posted 14 May 2004
Views 102,943
Bookmarked 60 times

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

By | 14 May 2004 | Article
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

About the Author

Mike Scanlon

Web Developer

United States United States

Member

Visit http://mike.pricklysoft.com


Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralThere is a WinApi function what does it ! Pinmemberadata29:57 10 Feb '11  
Generalrendering problems sometime PinmemberSergey Kolomenkin2:48 17 Mar '09  
Generalsource code Pinmemberstadelmann-peter6:32 17 Dec '08  
GeneralRe: source code Pinmemberdonor4:52 23 Dec '08  
GeneralWhere do I find the MsgBoxCheck.dll file PinmemberGlade Ross11:02 14 Jul '08  
GeneralRe: Where do I find the MsgBoxCheck.dll file PinmemberHantou10:40 30 Apr '09  
GeneralParameter to set the default button please PinmemberSuperCoder!3:16 19 Jun '08  
Mike
 
This is a handy little class. Any chance you could add a parameter that lets you set the default button.
 
For example, I am using the "Yes/No" buttons and the default button is the "Yes" button. I would like to have a parameter that allows me to set the "No" button as the default button...
 
You can contact me at howartthou@hotmail.com.
 
Regards
SuperCoder!

QuestionVista Problem PinmemberTurulo9:33 10 Apr '08  
AnswerRe: Vista Problem PinmemberSuperCoder!3:11 19 Jun '08  
GeneralLicense Attached Pinmemberrsbiz20041:07 26 Mar '08  
QuestionAnd in vbnet ? Pinmemberscalpa988:31 22 Sep '07  
AnswerRe: And in vbnet ? Pinmemberrsbiz20042:44 24 Mar '08  
Questionhow to use this from a visual c++ sln? Pinmemberlaura_glow10:06 13 Jun '07  
Generalimplementation to HTML Pinmemberjameo183:48 6 Jun '07  
GeneralMsgBoxCheck.dll source code or reg path Pinmemberwilsoada12:37 13 Dec '06  
GeneralDon't like the use of registry PinmemberPiotr Perak4:06 20 Oct '06  
GeneralRe: Don't like the use of registry Pinmembermanisys12:31 24 Mar '08  
GeneralSource Code PinmemberMArrington3:23 6 Feb '06  
GeneralRe: Source Code PinmemberMike Scanlon8:09 9 Feb '06  
GeneralWorked ok for me in VB.NET PinmemberDrogil15:33 20 Jul '05  
GeneralNot useful for me ... unless.. PinmemberBrett Swift6:00 25 May '05  
GeneralRe: Not useful for me ... unless.. PinmemberAngeliyo23:53 14 Jul '05  
GeneralRe: Not useful for me ... unless.. PinmemberBlazetopher9:18 3 Jul '06  
Generaluseful Pinmembersreejith ss nair18:09 2 Mar '05  
GeneralOne Thing I'd Like PinmemberDalan Galma14:34 16 Feb '05  

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.

Permalink | Advertise | Privacy | Mobile
Web02 | 2.5.120529.1 | Last Updated 15 May 2004
Article Copyright 2004 by Mike Scanlon
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid