Click here to Skip to main content
Click here to Skip to main content

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

By , 14 May 2004
 

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

 
Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralRe: Don't like the use of registrymembermanisys24 Mar '08 - 12:31 
GeneralSource CodememberMArrington6 Feb '06 - 3:23 
GeneralRe: Source CodememberMike Scanlon9 Feb '06 - 8:09 
GeneralWorked ok for me in VB.NETmemberDrogil20 Jul '05 - 15:33 
GeneralNot useful for me ... unless..memberBrett Swift25 May '05 - 6:00 
GeneralRe: Not useful for me ... unless..memberAngeliyo14 Jul '05 - 23:53 
GeneralRe: Not useful for me ... unless..memberBlazetopher3 Jul '06 - 9:18 
I had the same problem - I needed a YesNo messagebox, but it needed to reappear if No was selected - even if the checkbox was checked. I worked around the problem by catching the dialogresult and using a conditional statement, I simply deleted the key that was produced (if the checkbox was checked). This effectivly made it impossible to make a key when No was selected.
 
I'm pretty new to VS2005 (and programming in general for that matter), so it may be a "hack" workaround - but it works!
 
(i.e.)
DialogResult dr = ckMB.Show(strKey, "Answer", DialogResult.Yes, "Don't ask me this again", "This action will reset the color ramp and any changes will be lost.\nAre you sure you want to continue?","Are you sure?", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);

if (dr == DialogResult.No)
{
Registry.CurrentUser.DeleteSubKey(strKey,false);
...
}

 
Blazetopher
Generalusefulmembersreejith ss nair2 Mar '05 - 18:09 
GeneralOne Thing I'd LikememberDalan Galma16 Feb '05 - 14:34 
GeneralThis is easy to achievememberkonamiman3419 Nov '07 - 22:22 
GeneralGreat!memberMach00519 May '04 - 20:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

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