Click here to Skip to main content
14,969,910 members
Articles / Desktop Programming / Windows Forms
Posted 14 Dec 2006


47 bookmarked

Message Form - A Minimum Time Display Form

Rate me:
Please Sign up or sign in to vote.
4.97/5 (13 votes)
14 Dec 20063 min read
Display useful messages for a minimum duration

Image 1


When displaying a status message to the user, I don't like those messages that appear and disappear on the screen so fast you can't read them. I think that's poor form, and so I wrote a very simple classed derived from System.Windows.Form to display a modeless message for a controlled minimum amount of time. The code is ridiculously simple, and if you want to embellish it with anything more sophisticated, I'd suggest taking a look at Nish's MessageBoxManager.


The MessageForm class is derived from the System.Windows.Form class, so you can customize it just as any other form. The MessageForm will display indefinitely until one of the following occurs:

  • The application calls EndShow. The form will continue to display for the remaining required display time.
  • The application calls CancelShow. The form will be closed immediately.
  • The user closes the form.

The only thing the form displays is a centered Label docked to the extents of the form. If you want anything more interesting, such as adding a progress bar, you can change the MessageForm in the Visual Studio designer to suit your needs.



The MessageForm class implements the following properties:


Sets/gets the minimum display time for the form.


Sets/gets the message text, which is basically just a wrapper to setting the Text property of the form's Label control.


There are three constructors:

  • A default parameterless constructor
  • A constructor that takes only the message text as a parameter. The form caption will be blank unless set by the application before calling one of the BeginShow methods.
  • A constructor that takes the message text and caption text



/// <summary>
/// Show the form with the current minimum display time.
/// </summary>
public void BeginShow()
  expires = DateTime.Now.AddMilliseconds(minTime);

/// <summary>
/// Show the form for a minimum time.
/// </summary>
/// <param name="minDuration">The minimum display time, 
/// in milliseconds.</param>
public void BeginShow(int minDisplayTime)
  expires = DateTime.Now.AddMilliseconds(minDisplayTime);

The parameterless method shows the form, and uses the current MinTime value to determine the minimum display time for the form. There is a second BeginShow method that lets you override the MinTime value.


/// <summary>
/// Wait until the minimum display time has expired (which it may have) then
/// close the info message dialog. This is a thread blocking call.
/// </summary>
public void EndShow()
  TimeSpan remTime = expires - DateTime.Now;
  int remms = (int)remTime.TotalMilliseconds;

  if (remms > 0)


This method will not close the form until the minimum display time has expired. One important thing to note is that it is a blocking call, so your thread (such as the main application thread) will be suspended until the minimum display time has expired. This probably isn't ideal, but it's a complicated issue to deal with (not from an implementation point of view, but from the perspective of usability and user feedback) and is best left to the specific application requirements.


/// <summary>
/// Immediately close the info message.
/// </summary>
public void CancelShow()

CancelShow is really there just for consistency in the API. It will immediately close the form.


Calling DoEvents

If you call BeginShow as part of a long process that is occurring on the main application thread, you'll need to call Application.DoEvents immediately after the BeginShow for the form to properly display.

Using Form.Invoke

Don't forget that Windows likes to manipulate a window on the same thread that it was created on. Ideally, I would create the form on the main application thread and close it there as well, which may require wrapping the BeginShow and EndShow calls within a Form.Invoke delegate.


This is a very simple component, but I find it very re-usable and useful in the applications I write. I usually don't need anything too fancy and if I do, it's so application specific, but I still use this code as the starting point.


  • 14th December, 2006: Initial version


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

Marc Clifton
Architect Interacx
United States United States
Home Page:

All my life I have been passionate about architecture / software design, as this is the cornerstone to a maintainable and extensible application. As such, I have enjoyed exploring some crazy ideas and discovering that they are not so crazy after all. I also love writing about my ideas and seeing the community response. As a consultant, I've enjoyed working in a wide range of industries such as aerospace, boatyard management, remote sensing, emergency services / data management, and casino operations. I've done a variety of pro-bono work non-profit organizations related to nature conservancy, drug recovery and women's health.

Comments and Discussions

GeneralMy vote of 5 Pin
Manoj Kumar Choubey2-Mar-12 22:56
professionalManoj Kumar Choubey2-Mar-12 22:56 
QuestionPut Application.DoEvents in BeginShow? Pin
Richard_N14-Dec-06 10:01
MemberRichard_N14-Dec-06 10:01 
AnswerRe: Put Application.DoEvents in BeginShow? Pin
Marc Clifton14-Dec-06 11:17
mvaMarc Clifton14-Dec-06 11:17 
GeneralRe: Put Application.DoEvents in BeginShow? Pin
David Hay19-Dec-06 11:12
MemberDavid Hay19-Dec-06 11:12 

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.