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

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

Introduction

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)

yourMessage

the message you want to show

receiver

the control that will be used to invoke the delegate

pd

the delegate that will be invoked

arg

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.

History

  • 28 May 2004 - minor code update

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

Share

About the Author

fuad.abdallah
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.

Comments and Discussions

 
GeneralMy vote of 5 PinmemberLony Ma19-Dec-10 22:33 
QuestionStrange location problem Pinmemberz00z015-Oct-08 11:48 
General.NET 2.0 Upgrade Pinmemberhkeys26-Oct-06 10:54 
AnswerRe: .NET 2.0 Upgrade Pinmember@Jim1-Jul-07 6:17 
GeneralAlternative to passing Control PinmemberRichard Deeming1-Jun-04 7:56 
GeneralNew Version fixing focus Problem Pinmemberfuad.abdallah28-May-04 12:50 
GeneralFocus PinmemberJDBP27-May-04 15:48 
GeneralRe: Focus Pinmemberfuad.abdallah27-May-04 22:00 
GeneralRe: Focus PinmemberJDBP28-May-04 5:58 
GeneralRe: Focus Pinmemberfuad.abdallah28-May-04 8:06 

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
Web02 | 2.8.150327.1 | Last Updated 28 May 2004
Article Copyright 2004 by fuad.abdallah
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid