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

MessageBoxManager - A Windows Forms component that provides enhanced MessageBox functionality

, 19 Feb 2006 Ms-PL
Rate this:
Please Sign up or sign in to vote.
MessageBoxManager is a Windows Forms component that you can drag & drop into a Windows Forms project's main form, and it gives you enhanced message box functionality without forcing you to change your existing calls to any of the MessageBox.Show() overloads


MessageBoxManager is a Windows Forms component that you can drag & drop into a Windows Forms project's main form, and it gives you enhanced message box functionality without forcing you to change your existing calls to any of the MessageBox.Show() overloads. It supports various features such as an auto-closing message-box, such as the one shown in the animated GIF below. Note how the OK button is disabled during the count down, and gets enabled at the end of it. You can also see a Show this dialog again check box that has been added to the message-box. Once again, note you don't have to change your existing code that uses MessageBox.Show, or even code that P/Invokes the MessageBox or MessageBoxIndirect API function calls.

Other features include the ability to force a custom icon (over a default one), and this can be seen in the screenshots on top of this page, as well as the ability to set a custom font. When you set a custom font, the message-box and its child controls are expanded to adjust to the increase in font size. Note that, if you use injudicious font-sizes, you'll get unexpected results. The stretch algorithm assumes that the custom font size is within a reasonable range of values. Here's a screenshot that shows a custom font in action.

Using the class

Using the class is pretty straightforward as shown in the screenshot above. Just add the component to your toolbox, and drag & drop it into your main form. Only one instance of component should be used per application per thread. If you have a secondary thread that owns UI (such as a form for instance), that thread will need to have a separate instance of the MessageBoxManager component, and when the instance in the secondary thread is active, that in the primary thread *must be* temporarily disabled. Attempting to use multiple active MessageBoxManager objects from multiple threads or even from one thread will result in unexpected behavior and possibly affect program execution. The component consists entirely of properties (there are no instance methods outside of the compiler generated default constructor), and each of these properties can be directly set using the VS 2005 properties window (as in the above screenshot). The next section will quickly cover the functionality provided by each of these properties.

Class Reference

  • bool HookEnabled : Enables and disables the extended message box functionality. If this is false, your message-boxes will function as normal.

  • int TimeOut : This specifies the time-out in seconds that is used by the auto-close, button-disable, and title-countdown features.

  • bool AutoClose : Set this to true to close the message-box automatically after the number of seconds specified by the TimeOut property has elapsed.

  • DialogResult AutoCloseResult : When the AutoClose property is set, you can specify a DialogResult via this property that will be seen by the calling code (that invoked the message-box).

  • bool ShowTitleCountDown : If set to true, the title will show a count down and at the end of it, the original text will be restored.

  • bool DisableButtons : If set to true, during the count down (if any), all buttons except the Cancel button (if it's present) are disabled. Buttons are re-enabled when the count down has finished.

  • bool DisableCancel : If set to true, the Cancel button (if present) will be disabled if the DisableButtons property is also true. This property has no effect if the DisableButtons property is false.

  • bool CenterWindow : If true, the message-box is centered on its parent.

  • bool ShowNextTimeCheck : If this is set to true, a check box will be shown that prompts the user whether the dialog should be shown the next time. The message-box is resized to fit in this check box. The status of the check box is retrieved using the LastCheckState property.

  • bool LastCheckState : This returns the check state of the last message-box that was shown with a show-again check box. If you change the ShowNextTimeCheck to false, be aware that this property will continue will hold whatever value it had previously.

  • Font TextFont : You can set a custom font for the message-box and its controls, including the buttons. Use this feature with some basic sense of sagacity. The message-box is expanded to accomodate for the change in font-size (if any).

  • Icon CustomIcon : Set this to true to forcibly replace the message-box icon (if there's one present) with a custom icon. Note that all icons are blindly replaced if this property is true. This is handy if you want to show your product icon on all message-boxes shown from your application.


  • Feb 18 2006 - First version


This article, along with any associated source code and files, is licensed under The Microsoft Public License (Ms-PL)


About the Author

Nish Nishant

United States United States
Nish is a real nice guy who has been writing code since 1990 when he first got his hands on an 8088 with 640 KB RAM. Originally from sunny Trivandrum in India, he has been living in various places over the past few years and often thinks it’s time he settled down somewhere.
Nish has been a Microsoft Visual C++ MVP since October, 2002 - awfully nice of Microsoft, he thinks. He maintains an MVP tips and tricks web site - where you can find a consolidated list of his articles, writings and ideas on VC++, MFC, .NET and C++/CLI. Oh, and you might want to check out his blog on C++/CLI, MFC, .NET and a lot of other stuff -
Nish loves reading Science Fiction, P G Wodehouse and Agatha Christie, and also fancies himself to be a decent writer of sorts. He has authored a romantic comedy Summer Love and Some more Cricket as well as a programming book – Extending MFC applications with the .NET Framework.
Nish's latest book C++/CLI in Action published by Manning Publications is now available for purchase. You can read more about the book on his blog.
Despite his wife's attempts to get him into cooking, his best effort so far has been a badly done omelette. Some day, he hopes to be a good cook, and to cook a tasty dinner for his wife.

Comments and Discussions

QuestionDemo app problems PinprofessionalJohnny J.19-Sep-14 2:43 
AnswerRe: Demo app problems PinmvpNish Sivakumar22-Sep-14 9:09 
GeneralMy vote of 5 PinmemberFrancisco J. Rodríguez6-Oct-11 16:44 
GeneralMy vote of 5 PinmemberXmen W.K.19-Apr-11 16:14 
QuestionHow to use this Component Pinmemberpix_programmer7-Apr-11 0:03 
QuestionDo Not Show Again PinmemberDarth_Sebulba0423-Nov-09 7:09 
QuestionPlease Help.................... PinmemberMember 46731986-Mar-09 0:20 
GeneralAbout the back color of Messagebox PinmemberMikeylas19-Feb-09 16:00 
GeneralThis is nice! Pinmemberfinal_zero1-Sep-08 10:46 
QuestionCenter on parent not working? PinmemberConfuzerNL9-Jun-08 2:41 
Question"Show this dialog again?" ==> translate to german? PinmemberRalf Lenfers8-Apr-08 7:19 
GeneralTablet PC Support PinmemberMDThompson12-Nov-07 6:12 
GeneralRe: Tablet PC Support Pinmemberdbrenth24-Oct-08 8:52 
QuestionHow do you add MessageBoxManager component to the form? PinmemberCSharp20053-Oct-07 11:08 
QuestionCan it run under windows mobile 5.0? PinmembercastilloJeffersonS5-Feb-07 18:15 
QuestionProblem using the MessageBoxManager Pinmembert4urean10-Nov-06 6:12 
GeneralOne problem. Pinmemberjotaele31-Oct-06 2:21 
GeneralCreative! PinmemberPunCha29-Oct-06 21:09 
Generalool control - can it extended to dialogboxes PinmemberMartin Gartmann25-Jul-06 10:52 
GeneralCBT Hook Pinmembergabegabe14-Jun-06 2:40 
Generalappreciate this ! PinmemberBillWoodruff4-May-06 5:14 
QuestionDispose? PinmemberAlessio Forconi11-Mar-06 6:09 
AnswerRe: Dispose? PinmemberMister0330-Sep-07 9:40 
I use
MsgManager.HookEnabled = false;
after MessageBOx.Show();
Then it looks like it's back to null
GeneralNot working with W2K Pinmemberradzimskik2-Mar-06 12:59 
GeneralRe: Not working with W2K PinstaffNishant Sivakumar2-Mar-06 13:01 
GeneralRe: Not working with W2K Pinmemberradzimskik2-Mar-06 23:02 
GeneralVery Nice Pinmembercomputerguru9238225-Feb-06 12:21 
GeneralVS2003 PinmemberWilliam Ng22-Feb-06 14:10 
GeneralRe: VS2003 PinstaffNishant Sivakumar22-Feb-06 14:25 
GeneralGood job, eh! PinsitebuilderMichael Dunn21-Feb-06 12:30 
GeneralRe: Good job, eh! PinstaffNishant Sivakumar21-Feb-06 12:48 
GeneralWhy not in C++\CLI PinmemberRama Krishna Vavilala21-Feb-06 5:26 
GeneralRe: Why not in C++\CLI PinstaffNishant Sivakumar21-Feb-06 5:59 
GeneralDelicious! PinmemberKenGuru21-Feb-06 5:25 
GeneralRe: Delicious! PinstaffNishant Sivakumar21-Feb-06 6:00 
GeneralA great addition Pinmembermalharone20-Feb-06 9:31 
GeneralRe: A great addition PinstaffNishant Sivakumar21-Feb-06 6:00 
GeneralNice! PinprotectorMarc Clifton20-Feb-06 3:20 
GeneralRe: Nice! PinstaffNishant Sivakumar21-Feb-06 6:00 
GeneralVery nice! PinmemberBravid19-Feb-06 23:26 
GeneralRe: Very nice! PinstaffNishant Sivakumar20-Feb-06 2:22 
GeneralAweSome() PinmemberBinsNZ19-Feb-06 21:38 
GeneralRe: AweSome() PinstaffNishant Sivakumar20-Feb-06 2:22 

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
Web04 | 2.8.150327.1 | Last Updated 19 Feb 2006
Article Copyright 2006 by Nish Nishant
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid