Click here to Skip to main content
12,300,379 members (51,847 online)
Click here to Skip to main content
Add your own
alternative version


164 bookmarked

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 Nishant is a Software Architect/Consultant based out of Columbus, Ohio. He has over 16 years of software industry experience in various roles including Lead Software Architect, Principal Software Engineer, and Product Manager. Nish is a recipient of the annual Microsoft Visual C++ MVP Award since 2002 (14 consecutive awards as of 2015).

Nish is an industry acknowledged expert in the Microsoft technology stack. He authored
C++/CLI in Action for Manning Publications in 2005, and had previously co-authored
Extending MFC Applications with the .NET Framework for Addison Wesley in 2003. In addition, he has over 140 published technology articles on and another 250+ blog articles on his
WordPress blog. Nish is vastly experienced in team management, mentoring teams, and directing all stages of software development.

Contact Nish : You can reach Nish on his google email id voidnish.

Website and Blog

You may also be interested in...

Comments and Discussions

Question"Show this dialog again?" ==> translate to german? Pin
Ralf Lenfers8-Apr-08 6:19
memberRalf Lenfers8-Apr-08 6:19 
GeneralTablet PC Support Pin
MDThompson12-Nov-07 5:12
memberMDThompson12-Nov-07 5:12 
GeneralRe: Tablet PC Support Pin
dbrenth24-Oct-08 7:52
memberdbrenth24-Oct-08 7:52 
QuestionHow do you add MessageBoxManager component to the form? Pin
CSharp20053-Oct-07 10:08
memberCSharp20053-Oct-07 10:08 
QuestionCan it run under windows mobile 5.0? Pin
castilloJeffersonS5-Feb-07 17:15
membercastilloJeffersonS5-Feb-07 17:15 
QuestionProblem using the MessageBoxManager Pin
t4urean10-Nov-06 5:12
membert4urean10-Nov-06 5:12 
GeneralOne problem. Pin
jotaele31-Oct-06 1:21
memberjotaele31-Oct-06 1:21 
GeneralCreative! Pin
PunCha29-Oct-06 20:09
memberPunCha29-Oct-06 20:09 
Generalool control - can it extended to dialogboxes Pin
Martin Gartmann25-Jul-06 9:52
memberMartin Gartmann25-Jul-06 9:52 
GeneralCBT Hook Pin
gabegabe14-Jun-06 1:40
membergabegabe14-Jun-06 1:40 
Generalappreciate this ! Pin
BillWoodruff4-May-06 4:14
memberBillWoodruff4-May-06 4:14 
QuestionDispose? Pin
Alessio Forconi11-Mar-06 5:09
memberAlessio Forconi11-Mar-06 5:09 
AnswerRe: Dispose? Pin
Mister0330-Sep-07 8:40
memberMister0330-Sep-07 8:40 
GeneralNot working with W2K Pin
radzimskik2-Mar-06 11:59
memberradzimskik2-Mar-06 11:59 
GeneralRe: Not working with W2K Pin
Nishant Sivakumar2-Mar-06 12:01
staffNishant Sivakumar2-Mar-06 12:01 
GeneralRe: Not working with W2K Pin
radzimskik2-Mar-06 22:02
memberradzimskik2-Mar-06 22:02 
GeneralVery Nice Pin
computerguru9238225-Feb-06 11:21
membercomputerguru9238225-Feb-06 11:21 
GeneralVS2003 Pin
William Ng22-Feb-06 13:10
memberWilliam Ng22-Feb-06 13:10 
GeneralRe: VS2003 Pin
Nishant Sivakumar22-Feb-06 13:25
staffNishant Sivakumar22-Feb-06 13:25 
GeneralGood job, eh! Pin
Michael Dunn21-Feb-06 11:30
sitebuilderMichael Dunn21-Feb-06 11:30 
GeneralRe: Good job, eh! Pin
Nishant Sivakumar21-Feb-06 11:48
staffNishant Sivakumar21-Feb-06 11:48 
GeneralWhy not in C++\CLI Pin
Rama Krishna Vavilala21-Feb-06 4:26
memberRama Krishna Vavilala21-Feb-06 4:26 
GeneralRe: Why not in C++\CLI Pin
Nishant Sivakumar21-Feb-06 4:59
staffNishant Sivakumar21-Feb-06 4:59 
GeneralDelicious! Pin
KenGuru21-Feb-06 4:25
memberKenGuru21-Feb-06 4:25 
GeneralRe: Delicious! Pin
Nishant Sivakumar21-Feb-06 5:00
staffNishant Sivakumar21-Feb-06 5:00 
GeneralA great addition Pin
malharone20-Feb-06 8:31
membermalharone20-Feb-06 8:31 
GeneralRe: A great addition Pin
Nishant Sivakumar21-Feb-06 5:00
staffNishant Sivakumar21-Feb-06 5:00 
GeneralNice! Pin
Marc Clifton20-Feb-06 2:20
protectorMarc Clifton20-Feb-06 2:20 
GeneralRe: Nice! Pin
Nishant Sivakumar21-Feb-06 5:00
staffNishant Sivakumar21-Feb-06 5:00 
GeneralVery nice! Pin
Bravid19-Feb-06 22:26
memberBravid19-Feb-06 22:26 
GeneralRe: Very nice! Pin
Nishant Sivakumar20-Feb-06 1:22
staffNishant Sivakumar20-Feb-06 1:22 
GeneralAweSome() Pin
BinsNZ19-Feb-06 20:38
memberBinsNZ19-Feb-06 20:38 
GeneralRe: AweSome() Pin
Nishant Sivakumar20-Feb-06 1:22
staffNishant Sivakumar20-Feb-06 1:22 

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.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160525.2 | Last Updated 19 Feb 2006
Article Copyright 2006 by Nish Nishant
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid