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

NotifyWindow: A different MSN Messenger style notification window

, 2 Aug 2004
Rate this:
Please Sign up or sign in to vote.
Another MSN Messenger-like notification window, this one does its own drawing


NotifyWindow displays an MSN Messenger-like notification window. If you want to display your own images in the notification window, you may prefer to use John O'Byrne's TaskbarNotifer. NotifyWindow may be easier to use if you just intend to display text. Animations are used in opening and closing the NotifyWindow, and the window is displayed TopMost while not stealing focus. The window will be shown for a default of 11 seconds, although this can be changed. NotifyWindow does all of its own drawing, so no extra image files are required.

Using the code

It is pretty simple to display text using NotifyWindow.

// Display the text "This is a sample NotifyWindow"
NotifyWindow nw = new NotifyWindow ("This is a sample NotifyWindow");

// The following two lines of code will display a window that 
// looks exactly like the one shown at the beginning of this article.
NotifyWindow nw = new NotifyWindow ("NotifyWindow", 
  "This is a sample notification created with NotifyWindow");

If desired, a variety of other options can be changed - such as fonts and colors. The included TestNotifyWindow application will let you play around with a few of the settings, but the code displayed here should serve as a more complete reference.

NotifyWindow nw = new NotifyWindow();

nw.Text = "This is the NotifyWindow text";
nw.Title = "Title Text";

// Change the background style.  Other valid 
// styles are Solid, VerticalGradient,
// HorizontalGradient and BackwardDiagonalGradient  
// (Default: VerticalGradient)
nw.BackgroundStyle = NotifyWindow.BackgroundStyles.ForwardDiagonalGradient;

// Change the background colors  
// (Default: BackColor=SteelBlue, GradientColor=WhiteSmoke)
nw.BackColor = Color.SpringGreen;
nw.GradientColor = Color.White;

// Change the text and title colors.  (Default: ControlText)
nw.TextColor = Color.Blue;
nw.TitleColor = Color.Black;

// Change the color displayed when the text is pressed.  (Default: Gray)
nw.PressedColor = Color.Red;

// Use non-default fonts.  If TitleFont is not set 
// by the user, nw.Font will be used.
nw.Font = new Font ("Tahoma", 8.25F);
nw.TitleFont = new Font ("Tahoma", 8.25F, FontStyle.Bold);

// Change NotifyWindow size.  (Default: 130, 110)
nw.SetDimensions (nwWidth, nwHeight);

// Do not close the NotifyWindow if the mouse 
// cursor is over the window.  (Default: true)
nw.WaitOnMouseOver = true;

// Set up an EventHandler to be called if the text or title are clicked.
nw.TextClicked += new System.EventHandler (nwTextClicked);
nw.TitleClicked += new System.EventHandler (nwTitleClicked);

// Display the window for 20 seconds, or 20000ms.  (Default: 11000ms)
nw.WaitTime = 20000;

// Now show the NotifyWindow.

This is how the NotifyWindow created with the above code will look:

Programmers can also use their own Blend (for the background) or StringFormat (which will be used when Text and Title are drawn) if desired by setting the nw.Blend and nw.StringFormat variables.

Points of Interest

NotifyWindow is unique because it does all of its own drawing. The background is drawn using Graphics.FillRectangle with either a LinearGradientBrush (default) or a SolidBrush. The borders are drawn using a series of calls to Graphics.DrawRectangle and Graphics.DrawLine. On Windows XP or higher systems with Visual Styles enabled, the close button is drawn using DrawThemeBackground() from UxTheme.dll - otherwise, ControlPaint.DrawCaptionButton is used.

An obstacle faced in both this and similar applications has been displaying the window on top without stealing focus. Both Form.Show() and setting TopMost = true individually activate the form, which steals focus. We get around this by calling ShowWindow() and SetWindowPos() with arguments instructing the operating system not to activate the window.

const Int32 HWND_TOPMOST = -1;
const Int32 SWP_NOACTIVATE = 0x0010;
const Int32 SW_SHOWNOACTIVATE = 4;
[DllImport ("user32.dll")]
protected static extern bool ShowWindow (IntPtr hWnd, Int32 flags);
[DllImport ("user32.dll")]
protected static extern bool SetWindowPos (IntPtr hWnd, 
  Int32 hWndInsertAfter, Int32 X, Int32 Y, Int32 cx, Int32 cy, uint uFlags);


// Show the window without activating it.
ShowWindow (this.Handle, SW_SHOWNOACTIVATE);

// Equivalent to setting TopMost = true, except don't activate the window.
SetWindowPos (this.Handle, HWND_TOPMOST, Left, Top, Width, Height, SWP_NOACTIVATE);

A similar NotifyWindow class was originally implemented for an open-source project called ChronosXP. When it became apparant that others might like to use this code outside of that project, it was modified, removing the ChronosXP-specific parts and making it more generic.

A class called NotifyWindow2000 is included with the distribution that will display the NotifyWindow indefinitely until there is mouse or keyboard activity, similar to balloon windows. It uses SetWindowsHookEx() with WH_KEYBOARD_LL/WH_MOUSE_LL to detect user activity, so it will only work with Windows 2000 or higher. If anyone knows how to do this on older versions of Windows I would like to hear about it.


  • Initial coding: July 28, 2004


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

Robert Misiak
Architect Onestop Internet
United States United States
Web architect and PM, in the E-commerce space.
Follow on   LinkedIn

Comments and Discussions

QuestionGood idea! Pinmembercen_jin_long7-Mar-13 13:21 
GeneralMy vote of 5 PinmemberRafik El-Kheer3-Aug-12 15:49 
Questioni want to hide CLOSE button on NotifyWindow......what to do? PinmemberRobin Purbia12-Jul-12 1:48 
AnswerRe: i want to hide CLOSE button on NotifyWindow......what to do? PinmemberMember 114928152-Mar-15 14:34 
QuestionNotifyWindows PinmemberPunisher935-Mar-12 8:32 
QuestionHeartly thank you PinmemberAnil B. Patil22-Feb-12 19:16 
Thank you very very much....
Your coding is so nice....
GeneralMy vote of 5 Pinmemberamitmane55528-Feb-11 0:41 
GeneralNotification window won't close Pinmembermike Svidron30-Apr-10 7:12 
QuestionHow can i just show notification window not form window Pinmembername3221-Apr-10 3:56 
AnswerRe: How can i just show notification window not form window PinmemberMember 114928152-Mar-15 14:33 
GeneralQuestion PinmemberBenjamin Unanka24-Jul-08 7:42 
QuestionVB.Net version? Pinmembercal1918-Apr-08 3:08 
AnswerRe: VB.Net version? Pinmemberrzeylah6-Aug-08 1:29 
GeneralRe: VB.Net version? Pinmemberpaladinkerb30-Mar-11 10:01 
GeneralUnable to download NotifyWindow PinmemberGlauter7-Mar-08 5:12 
GeneralNotifyWindow on Vista Pinmemberpogarek15-Feb-07 23:13 
GeneralRe: NotifyWindow on Vista PinmemberRobert Misiak10-Jul-07 9:19 
QuestionHow to Add a Control Pinmemberraj_32722-Jan-07 21:30 
GeneralShow two NotifyWindows above each other PinmemberLpH198126-May-06 1:41 
GeneralRe: Show two NotifyWindows above each other Pinmemberronaldovn17-Mar-10 22:17 
GeneralRe: Show two NotifyWindows above each other PinmemberLucas heezen18-Mar-10 1:59 
GeneralRe: Show two NotifyWindows above each other Pinmemberronaldovn18-Mar-10 17:24 
GeneralRe: Show two NotifyWindows above each other PinmemberDekkie17-Feb-11 5:52 
QuestionUsing notify window in a ThreadFunction Pinmemberjis17-May-06 3:36 
AnswerRe: Using notify window in a ThreadFunction PinmemberRobert Misiak17-May-06 4:19 
GeneralRe: Using notify window in a ThreadFunction Pinmemberjis17-May-06 19:41 
GeneralRe: Using notify window in a ThreadFunction PinmemberManjit Sooch20-Jul-06 14:33 
GeneralRe: Using notify window in a ThreadFunction Pinmembershane198527-Sep-07 10:21 
GeneralRe: Using notify window in a ThreadFunction Pinmemberlxiongh3-Sep-09 5:03 
GeneralRe: Using notify window in a ThreadFunction PinmemberLeoLB12-Jun-13 9:10 
GeneralStacking windows code Pinmemberjdmwood29-Mar-06 1:13 
GeneralRe: Stacking windows code Pinmemberjdmwood29-Mar-06 1:16 
GeneralRe: Stacking windows code PinmemberBob-ish11-Dec-06 13:51 
GeneralRe: Stacking windows code PinmemberPooranPrasad8-Apr-07 22:54 
GeneralRe: Stacking windows code Pinmembern2jtx15-Apr-08 8:27 
GeneralRe: Stacking windows code Pinmemberronaldovn18-Mar-10 17:40 
GeneralRe: Stacking windows code Pinmemberronaldovn18-Mar-10 18:55 
QuestionHow would you call this from a C# ASP.Net Web Application Pinmembermranimal25-Feb-06 10:11 
AnswerRe: How would you call this from a C# ASP.Net Web Application PinmemberPaulza26-Jan-07 0:37 
GeneralGood jumping off point! Pinmemberdavegalligher26-Jan-06 11:06 
GeneralNative Window Pinmemberhandle1237-Dec-05 21:22 
GeneralRe: Native Window PinmemberRobert Misiak8-Dec-05 3:49 
GeneralRe: Native Window Pinmemberpjnaughter12-May-06 4:59 
GeneralVery Leaky PinmemberMatware7-Nov-05 19:33 
GeneralRe: Very Leaky PinmemberRobert Misiak8-Dec-05 3:48 
GeneralRe: Very Leaky PinmemberMember 469789318-Sep-08 9:46 
GeneralImage Display Pinmembersuresh_unique18-Aug-05 5:46 
GeneralRe: Image Display PinmemberMarkoStamcar30-Nov-05 13:54 
QuestionOpacity? PinmemberDarenIott14-Jul-05 6:55 
AnswerRe: Opacity? PinmemberRobert Misiak14-Jul-05 7:20 

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
Web01 | 2.8.150331.1 | Last Updated 3 Aug 2004
Article Copyright 2004 by Robert Misiak
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid