Click here to Skip to main content
16,015,296 members
Articles / Desktop Programming / Windows Forms
Article

An Office 2003-like popup notifier

Rate me:
Please Sign up or sign in to vote.
4.71/5 (58 votes)
23 Mar 2006CPOL1 min read 315.7K   7.1K   182   113
A nice little control to help the user notice you're trying to tell him something...

Image 1

Introduction

This is a simple project, a control that mimics the Microsoft® Outlook® 2003 mail alert.

Features

This control has several features. Among them, you'll find:

Image 2

Progressive appearance - transparency

Image 3

MSN Messenger like pop-ups (any size, color, etc.)

Image 4

Another sample

This control is 100% drawn in the code, there is absolutely no other dependencies than System.Drawing and System.Windows.Forms.

You can include a ContextMenuStrip when clicking on the "down arrow" button.

Using the code

The controls is made of two basic classes:

  • A form (the part that will actually show up).
  • A class that contains all the properties that will be includable on forms.

The class contains two timers, one used for the appearing/disappearing animation, the other (configurable) is used to define how much time the popup is shown before it disappears.

This is how the form is actually shown:

VB
fPopup.Size = Size
fPopup.Opacity = 0
fPopup.Location = _
  New Point(Screen.PrimaryScreen.WorkingArea.Right_
   - fPopup.Size.Width - 1, _
   Screen.PrimaryScreen.WorkingArea.Bottom)
fPopup.Show()

The form is does the drawing in the Paint event.

I'm using these functions to obtain a color that is similar but lighter/darker. There might exist another method.

VB
Private Function GetDarkerColor(ByVal Color As Color) As Color
    Dim clNew As Color
    clNew = Drawing.Color.FromArgb(255, DedValueMin0(CInt(Color.R), _
            Parent.GradientPower), DedValueMin0(CInt(Color.G), _
            Parent.GradientPower), DedValueMin0(CInt(Color.B), _
            Parent.GradientPower))
    Return clNew
End Function

And to avoid flickering...

VB
Me.SetStyle(ControlStyles.OptimizedDoubleBuffer, True)
Me.SetStyle(ControlStyles.ResizeRedraw, True)
Me.SetStyle(ControlStyles.AllPaintingInWmPaint, True)

Points of Interest

None really, it's nice, it's fun, it's colorful... that's it :)

History

  • March 2006 - V 1.0.

License

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


Written By
Software Developer (Senior)
Switzerland Switzerland
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralRe: ShowInTaskbar = False Pin
Nicolas Wälti30-Mar-06 2:38
Nicolas Wälti30-Mar-06 2:38 
GeneralRe: ShowInTaskbar = False Pin
Hector C30-Mar-06 5:02
Hector C30-Mar-06 5:02 
GeneralVery nice! Pin
Hector C29-Mar-06 6:39
Hector C29-Mar-06 6:39 
GeneralRe: Very nice! Pin
Nicolas Wälti30-Mar-06 2:42
Nicolas Wälti30-Mar-06 2:42 
GeneralGood Job Pin
KentuckyEnglishman29-Mar-06 3:22
KentuckyEnglishman29-Mar-06 3:22 
GeneralRe: Good Job Pin
Nicolas Wälti29-Mar-06 3:54
Nicolas Wälti29-Mar-06 3:54 
QuestionMSN-like stackable popup Pin
Lars MSLS29-Mar-06 11:38
Lars MSLS29-Mar-06 11:38 
AnswerRe: MSN-like stackable popup Pin
Nicolas Wälti30-Mar-06 2:38
Nicolas Wälti30-Mar-06 2:38 
Actually, you can write a wrapper class such as PopupNotifierCollection:
Imports System.ComponentModel

Public Class PopupNotifierCollection
    Inherits CollectionBase

    Sub New()

    End Sub

    Protected Overrides Sub OnSet(ByVal index As Integer, ByVal oldValue As Object, ByVal newValue As Object)
        MyBase.OnSet(index, oldValue, newValue)
    End Sub

    Protected Overrides Sub OnInsert(ByVal index As Integer, ByVal value As Object)
        MyBase.OnInsert(index, value)
    End Sub

    Default ReadOnly Property Item(ByVal Index As Integer) As PopupNotifier
        Get
            Return DirectCast(List(Index), PopupNotifier)
        End Get
    End Property

    Public Function Add(ByVal value As PopupNotifier) As PopupNotifier
        List.Add(value)
        Return value
    End Function

    Public Function Contains(ByVal value As PopupNotifier) As Boolean
        Return List.Contains(value)
    End Function

    Public Sub Remove(ByVal value As PopupNotifier)
        List.Remove(value)
    End Sub

    Public Function IndexOf(ByVal value As PopupNotifier) As Integer
        Return List.IndexOf(value)
    End Function

    Public Shadows Sub Clear()
        MyBase.Clear()
    End Sub

    Sub Popup()
        For Each Item As PopupNotifier In List
            Item.Popup(List.IndexOf(Item))
        Next
        Clear()
    End Sub

End Class

With that class, you can just create a PopupNotifier and add it to the collection using
Dim colPopupNotifiers As New PopupNotifierCollection
Dim pnNotifier1 As PopupNotifier = New PopupNotifier
Dim pnNotifier2 As PopupNotifier = New PopupNotifier

colPopupNotifiers.Add(pnNotifier1)
colPopupNotifiers.Add(pnNotifier2)

colPopupNotifiers.Popup()

Calling the Popup() function will call the function of the PopupNotifier.
Then, PopupNotifier needs also some slight modification:
First add a iOffset variable (integer)
Private iOffset As Integer = 0

Then set it and use it in the Popup() function:
Sub Popup(Optional ByVal Number As Integer = 0)
    tmWait.Interval = ShowDelay
    fPopup.Size = Size
    fPopup.Opacity = 0
    iOffset = (Number * fPopup.Size.Height) + (Number * 5)
    fPopup.Location = New Point(Screen.PrimaryScreen.WorkingArea.Right - fPopup.Size.Width - 1, Screen.PrimaryScreen.WorkingArea.Bottom - iOffset)
    fPopup.Show()
    tmAnimation.Start()
End Sub

Notice here, we are using a offset that is the height of the form times the index of the PopupNotifier in the collection.
Then in tmAnimation_Tick(), we also need to add the offset:
...
If fPopup.Top + fPopup.Height < Screen.PrimaryScreen.WorkingArea.Bottom - iOffset
...
If fPopup.Top > Screen.PrimaryScreen.WorkingArea.Bottom - iOffset
...

Hope this solution will be enough for you...

Cheers,
Nick
GeneralRe: MSN-like stackable popup Pin
Lars MSLS30-Mar-06 11:03
Lars MSLS30-Mar-06 11:03 
GeneralRe: MSN-like stackable popup Pin
Nicolas Wälti30-Mar-06 12:08
Nicolas Wälti30-Mar-06 12:08 
GeneralRe: MSN-like stackable popup Pin
Lars MSLS31-Mar-06 11:17
Lars MSLS31-Mar-06 11:17 
GeneralRe: MSN-like stackable popup Pin
Nicolas Wälti2-Apr-06 7:25
Nicolas Wälti2-Apr-06 7:25 
GeneralAnimation Delay Pin
Danilo Corallo27-Mar-06 21:18
Danilo Corallo27-Mar-06 21:18 
GeneralRe: Animation Delay Pin
Nicolas Wälti27-Mar-06 22:06
Nicolas Wälti27-Mar-06 22:06 
Generalvery nice Pin
AnasHashki25-Mar-06 21:57
AnasHashki25-Mar-06 21:57 
GeneralRe: very nice Pin
Nicolas Wälti27-Mar-06 22:07
Nicolas Wälti27-Mar-06 22:07 
Generalits Amazing Pin
Sudhir Mangla23-Mar-06 18:56
professionalSudhir Mangla23-Mar-06 18:56 
GeneralRe: its Amazing Pin
Nicolas Wälti27-Mar-06 22:08
Nicolas Wälti27-Mar-06 22:08 
GeneralRe: its Amazing Pin
Moustafa Arafa15-May-06 21:13
Moustafa Arafa15-May-06 21:13 
GeneralHide Pin
o_pontios23-Mar-06 14:09
o_pontios23-Mar-06 14:09 
GeneralRe: Hide Pin
Nicolas Wälti24-Mar-06 3:44
Nicolas Wälti24-Mar-06 3:44 
GeneralRe: Hide Pin
HydroEric28-Mar-06 3:51
HydroEric28-Mar-06 3:51 
GeneralRe: Hide Pin
Nicolas Wälti28-Mar-06 5:57
Nicolas Wälti28-Mar-06 5:57 
GeneralRe: Hide Pin
CMTietgen10-Aug-06 15:01
CMTietgen10-Aug-06 15:01 
GeneralRe: Hide Pin
Davor K.27-Nov-08 7:30
Davor K.27-Nov-08 7:30 

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.