Click here to Skip to main content
13,044,705 members (44,158 online)
Click here to Skip to main content
Add your own
alternative version


43 bookmarked
Posted 28 Jan 2004

PI, a small but helpful popup info implemented in C#

, 27 May 2004
Rate this:
Please Sign up or sign in to vote.
A component for popup infos with configurable lifetime and callback features.

Sample Image - PI.gif


One of the many small utilities that are probably reinvented every day is a user notification in a small popup window.

Typical usages are email notifications or status messages for long running processes. After joining the club of re-inventers, I hope to simplify the tasks for some readers by writing this article and submitting my solution called PI (very imaginative short for PopupInfo).

Using the code

I tried to make using PI easy. Just add the PopupMessageHandler Component to your application and call:

AddMessage(String yourMessage)

to start a new popup info.

The Component comes with designer support, so customization should be fairly easy.

The popup windows appears at the lower right corner of the screen just above the taskbar and will disappear after a configurable time span.

Some care had to be taken to handle multiple popup windows. Of course, they should not overlap and the number of windows displayed simultaneously must be limited. The very simple solution to this is using a queue to store messages that must wait for free space. Clicking a popup info usually signals that the user has seen it, so it can be closed. This can open a gap in our nice pile of windows that must be closed. Windows above a gap have to drop into the free space, waiting messages will be displayed on top of the stack.

Now, to a more complex aspect - getting messages back from the popup windows. For this, more information is required and a second version of the AddMessage method has the additional parameters to specify what should happen if the user clicks on a message.

public void AddMessage(String yourMessage, 
      Control receiver, PIDelegate pd, object arg)


the message you want to show


the control that will be used to invoke the delegate


the delegate that will be invoked


an object that will be passed with the delegate

The test program shows an example for this call. The required delegate has the form:

public delegate void PIDelegate(object data)

Two more variants of AddMessage exist, with an additional int parameter that defines the time to live of the popups. If not specified, the component default ttl will be used.

Points of Interest

One tricky thing in the implementation was thread synchronization. The popup messages do run in their own threads (taken from a ThreadPool) and need to invoke a method in the main thread of a control. Fortunately, the control class contains several methods to perform this task and in this case, BeginInvoke was used.

The main loop of the PopupMessageHandler runs in a background thread that waits for a signal, if no messages are present. The AddMessage methods lock the queue that is used to store popup infos, so they are thread safe.


  • 28 May 2004 - minor code update


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

Web Developer
Germany Germany
After studying chemistry and biochemistry i received my PhD at the Max-Planck Society in Biochemistry/Bioinformatics. For the last 3 Years i have been working in a German Bioinformatics Company.
My main interests are biological databases and Workflow-Tools.

You may also be interested in...


Comments and Discussions

GeneralMy vote of 5 Pin
Lony Ma19-Dec-10 21:33
memberLony Ma19-Dec-10 21:33 
QuestionStrange location problem Pin
z00z015-Oct-08 10:48
memberz00z015-Oct-08 10:48 
General.NET 2.0 Upgrade Pin
hkeys26-Oct-06 9:54
memberhkeys26-Oct-06 9:54 
AnswerRe: .NET 2.0 Upgrade Pin
@Jim1-Jul-07 5:17
member@Jim1-Jul-07 5:17 
GeneralAlternative to passing Control Pin
Richard Deeming1-Jun-04 6:56
memberRichard Deeming1-Jun-04 6:56 
GeneralNew Version fixing focus Problem Pin
fuad.abdallah28-May-04 11:50
memberfuad.abdallah28-May-04 11:50 
GeneralFocus Pin
JDBP27-May-04 14:48
memberJDBP27-May-04 14:48 
GeneralRe: Focus Pin
fuad.abdallah27-May-04 21:00
memberfuad.abdallah27-May-04 21:00 
GeneralRe: Focus Pin
JDBP28-May-04 4:58
memberJDBP28-May-04 4:58 
GeneralRe: Focus Pin
fuad.abdallah28-May-04 7:06
memberfuad.abdallah28-May-04 7:06 
GeneralRe: Focus Pin
fuad.abdallah28-May-04 7:01
memberfuad.abdallah28-May-04 7:01 
GeneralRe: Focus Pin
JDBP28-May-04 7:29
memberJDBP28-May-04 7:29 
GeneralRe: Focus Pin
JDBP28-May-04 8:29
memberJDBP28-May-04 8:29 
GeneralRe: Focus Pin
@Jim1-Jul-07 5:20
member@Jim1-Jul-07 5:20 
GeneralThreads Pin
JDBP27-May-04 5:49
memberJDBP27-May-04 5:49 

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.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.170713.1 | Last Updated 28 May 2004
Article Copyright 2004 by fuad.abdallah
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid