Click here to Skip to main content
14,212,177 members
Click here to Skip to main content
Posted 1 Sep 2008


85 bookmarked


Rate this:
4.36 (10 votes)
Please Sign up or sign in to vote.
4.36 (10 votes)
1 Sep 2008     CPOL    
Notifier: an Outlook-like notification window


This article provides a popup-less notification window, and saves the user from the "Click-on-the-OK-button-to-continue" pain.


When using Microsoft Outlook, you come across a mail notification window that appears slowly and fades off. But, when you drop your mouse back on the window, it becomes opaque, and then again on mouse away, it fades off, and this process continues. So, eventually, it either fades away or you ignore the window, or you close it or you click it to read the mail. This article describes how to build that kind of a window using C#.

The Logic

The following are the steps involved:

  1. Make opacity level 0 initially.
  2. Display window.
  3. Start to show timer T1.
  4. Gradually increase the opacity in T1 until it reaches a maximum level 1.0.
  5. Stop timer T1.
  6. Start the hiding timer T2.
  7. Decrease the opacity level in T2 until it reaches the minimum level 0.01.
  8. Stop timer T2.
  9. Clean the message.
  10. Close the window.

Using the Code

The basic class that implements the logic is KNotifio.

Hide the Notification Window Timer

The hide timer event goes as follows:

privatevoid tmrHide_Tick(object sender, EventArgs e)
   //Decrease the opacity level until its greater than zero
   if (this.Opacity > 0.00)
      this.Opacity -= 0.01;
      //Window has gone completely transparent
      tmrHide.Stop();    //Stop the timer
      CloseWnd();        //Close window

Show the Notification Window Timer

The show timer event goes as follows:

private void tmrShow_Tick(object sender, EventArgs e)
   //Increase opacity until it reaches maximum
   if (this.Opacity < 0.99)
      this.Opacity += 0.01;
      //Window already opaque
      tmrShow.Stop();     //Let's stop the timer

      tmrHide.Start();    //Start hiding the window

Closing the Notification Window

Following is how the window is closed:

private void CloseWnd()
      //Stop timers

      g_Fio.Close();                          //Close the form
      m_strPreviousMessage = string.Empty;    //Clean message
   catch (Exception exec) { }

How the Window is Shown

public static void Show(string strMessage, i nShowTime, int nHideTime)
   //Set the time it should take to show the window
   m_nShowTime = nShowTime - 5;
   //Set the time it would take to hide the window
   m_nHideTime = nHideTime;

The Show() Method

public static void Show(string strMessage)
      if (m_strPreviousMessage == strMessage)
         m_strPreviousMessage = strMessage;
         KNotifio theNotifio = new KNotifio();
         g_Fio = theNotifio;
         theNotifio.txtMessage.Text = strMessage;
   catch (Exception exc)


public KNotifio()
   tmrHide.Interval = m_nHideTime;    //Set timers
   tmrShow.Interval = m_nShowTime;

      //Set round rects
   } catch (Exception exc) { }

   //Move window close to system tray (above the clock)
   Location = new Point(Screen.PrimaryScreen.Bounds.Width -
      this.Width, Screen.PrimaryScreen.Bounds.Height -
      this.Height - 50);

Rounded Corners

We call an API to make the corners round.

/// <span class="code-SummaryComment"><summary></span>
/// Provides MS Outlook styled dynamic notification window
/// <span class="code-SummaryComment"></summary></span>
public partial class KNotifio : Form
   //Need to make our window a bit rounded.
   [DllImport("Gdi32.dll", EntryPoint = "CreateRoundRectRgn")]
   private static extern IntPtr CreateRoundRectRgn
      int nLeftRect,        // x-coordinate of upper-left corner
      int nTopRect,         // y-coordinate of upper-left corner
      int nRightRect,       // x-coordinate of lower-right corner
      int nBottomRect,      // y-coordinate of lower-right corner
      int nWidthEllipse,    // height of ellipse
      int nHeightEllipse    // width of ellipse

Points of Interest

User specific window animations can be set. Similarly, for instance, the message type is critical information, and the box can made blinking, etc. The control can be made more animated, user focused, and we only would need to set the AnimationTypes.Warning tags.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Team Leader
Pakistan Pakistan
Interesting technologies:
.NET, RIA, EIA, SOAP, XML, LINQ, WCF, WPF, Silverlight, ASP.NET MVC, jQuery, CSS, HTML5.

Interesting products:
MOSS 2010, Microsoft Dynamics CRM 2010

Comments and Discussions

GeneralSeperate Thread Question Pin
EdP244-Feb-10 6:52
memberEdP244-Feb-10 6:52 
GeneralMy vote of 2 Pin
AKeck1-Feb-10 4:37
memberAKeck1-Feb-10 4:37 
GeneralGood work Pin
Dinesh Mani7-Sep-08 18:08
memberDinesh Mani7-Sep-08 18:08 
GeneralRe: Good work Pin
syntaxed4-Mar-09 1:27
membersyntaxed4-Mar-09 1:27 

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.

Layout: fixed | fluid

Article Copyright 2008 by syntaxed
Everything else Copyright © CodeProject, 1999-2019

Server Web01
Version 2.8.190619.2