Click here to Skip to main content
15,888,610 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 305.3K   7K   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

 
NewsRedundant Line of Code Pin
pablleaf21-Jun-07 10:38
pablleaf21-Jun-07 10:38 
GeneralSmall Doubt Pin
GayuDams26-Apr-07 2:05
GayuDams26-Apr-07 2:05 
GeneralOpacity Problem with multiple stacking popups Pin
fperugini22-Mar-07 10:18
fperugini22-Mar-07 10:18 
AnswerRe: Opacity Problem with multiple stacking popups Pin
fperugini23-Mar-07 4:33
fperugini23-Mar-07 4:33 
QuestionRe: Opacity Problem with multiple stacking popups Pin
Styxke5-Apr-07 20:27
Styxke5-Apr-07 20:27 
AnswerRe: Opacity Problem with multiple stacking popups Pin
fperugini13-Apr-07 7:16
fperugini13-Apr-07 7:16 
GeneralMultiple Highlight Lines Pin
b00tleg22-Mar-07 9:38
b00tleg22-Mar-07 9:38 
AnswerRe: Multiple Highlight Lines Pin
Nicolas Wälti22-Mar-07 22:34
Nicolas Wälti22-Mar-07 22:34 
In fact, I've not been using other controls on that form. The form is a placeholder.

Its content is only painted and is not "existing".

You can see for instance in PopupNotifierRenderersOffice2003.vb

<br />
    Protected Overrides Sub OnRenderContent(ByVal e As PopupNotifierRenderArgs)<br />
        If Not e.Parent.Image Is Nothing Then<br />
            e.Graphics.DrawImage(e.Parent.Image, e.Parent.ImagePosition.X, e.Parent.ImagePosition.Y, e.Parent.ImageSize.Width, e.Parent.ImageSize.Height)<br />
        End If<br />
<br />
        e.Parent.Form.HeightOfTitle = e.Graphics.MeasureString("A", e.Parent.TitleFont).Height<br />
<br />
        Dim iTitleOrigin As Integer<br />
        If Not e.Parent.Image Is Nothing Then<br />
            iTitleOrigin = e.Parent.ImagePosition.X + e.Parent.ImageSize.Width + e.Parent.TextPadding.Left<br />
        Else<br />
            iTitleOrigin = e.Parent.TextPadding.Left<br />
        End If<br />
<br />
        If e.Parent.Form.MouseIsOnTextLink Then<br />
            e.Parent.Form.Cursor = Cursors.Hand<br />
            e.Graphics.DrawString(e.Parent.ContentText, New Font(SystemFonts.DialogFont, FontStyle.Underline), New SolidBrush(Color.Black), e.Parent.Form.RectText)<br />
        Else<br />
            e.Parent.Form.Cursor = Cursors.Default<br />
            e.Graphics.DrawString(e.Parent.ContentText, New Font(SystemFonts.DialogFont, FontStyle.Regular), New SolidBrush(Color.Black), e.Parent.Form.RectText)<br />
        End If<br />
        e.Graphics.DrawString(e.Parent.TitleText, New Font(SystemFonts.DialogFont, FontStyle.Bold), New SolidBrush(Color.Black), iTitleOrigin, e.Parent.TextPadding.Top + e.Parent.HeaderHeight)<br />
    End Sub<br />


There is a call to e.Graphics.Drawstring to print the text link and there is a variable that is set by PopupNotifier to define whether we are on the link with the mouse or not. If you just want to have another link, you need to double that feature.
<br />
        If e.Parent.Form.MouseIsOnSecondTextLink Then<br />
            e.Parent.Form.Cursor = Cursors.Hand<br />
            e.Graphics.DrawString(e.Parent.SecondContentText, New Font(SystemFonts.DialogFont, FontStyle.Underline), New SolidBrush(Color.Black), e.Parent.Form.RectSecondText)<br />
        Else<br />
            e.Parent.Form.Cursor = Cursors.Default<br />
            e.Graphics.DrawString(e.Parent.SecondContentText, New Font(SystemFonts.DialogFont, FontStyle.Regular), New SolidBrush(Color.Black), e.Parent.Form.SecondRectText)<br />
        End If<br />


then in PopupNotifier.vb:
<br />
    Private sText2 As String<br />
    <Category("Content")> _<br />
    Property SecondContentText() As String<br />
        Get<br />
            Return sText2<br />
        End Get<br />
        Set(ByVal value As String)<br />
            sText2 = value<br />
<br />
        End Set<br />
    End Property<br />

And then for PopupNotifierForm.vb:

<br />
    Public ReadOnly Property SecondRectText() As RectangleF<br />
        Get<br />
            If Not Parent.Image Is Nothing Then<br />
                Return New RectangleF(Parent.ImagePosition.X + Parent.ImageSize.Width + Parent.TextPadding.Left, Parent.TextPadding.Top + Parent.TextPadding.Top + HeightOfTitle + Parent.HeaderHeight + RectText.Height, Me.Width - Parent.ImageSize.Width - Parent.ImagePosition.X - 16 - 5 - Parent.TextPadding.Left - Parent.TextPadding.Right, Me.Height - Parent.HeaderHeight - Parent.TextPadding.Top - Parent.TextPadding.Top - Parent.TextPadding.Bottom - HeightOfTitle - 1)<br />
            Else<br />
                Return New RectangleF(Parent.TextPadding.Left, Parent.TextPadding.Top + Parent.TextPadding.Top + HeightOfTitle + Parent.HeaderHeight + RectText.Height , Me.Width - 16 - 5 - Parent.TextPadding.Left - Parent.TextPadding.Right, Me.Height - Parent.HeaderHeight - Parent.TextPadding.Top - Parent.TextPadding.Top - Parent.TextPadding.Bottom - HeightOfTitle - 1)<br />
            End If<br />
        End Get<br />
    End Property<br />

Then alors in the mouse_move event
<br />
        If SecondRectText.Contains(e.X, e.Y) Then<br />
            bMouseOnLink2 = True<br />
        Else<br />
            bMouseOnLink2 = False<br />
        End If<br />


And that should pretty much do the trick Smile | :)
GeneralRe: Multiple Highlight Lines Pin
b00tleg23-Mar-07 7:04
b00tleg23-Mar-07 7:04 
GeneralRe: Multiple Highlight Lines Pin
Honey Arora23-May-07 19:29
Honey Arora23-May-07 19:29 
GeneralC# version Pin
Ambili_T21-Mar-07 22:23
Ambili_T21-Mar-07 22:23 
AnswerRe: C# version Pin
LittleWhiteDog22-Mar-07 21:33
LittleWhiteDog22-Mar-07 21:33 
QuestionHowto move the popup with the grip? Pin
LittleWhiteDog14-Mar-07 5:32
LittleWhiteDog14-Mar-07 5:32 
AnswerRe: Howto move the popup with the grip? Pin
Nicolas Wälti15-Mar-07 2:42
Nicolas Wälti15-Mar-07 2:42 
QuestionRe: Howto move the popup with the grip? [modified] Pin
LittleWhiteDog21-Mar-07 5:20
LittleWhiteDog21-Mar-07 5:20 
QuestionExtract the image Pin
LittleWhiteDog13-Mar-07 22:54
LittleWhiteDog13-Mar-07 22:54 
AnswerRe: Extract the image Pin
Nicolas Wälti15-Mar-07 2:41
Nicolas Wälti15-Mar-07 2:41 
NewsRe: Extract the image [modified] Pin
LittleWhiteDog15-Mar-07 23:22
LittleWhiteDog15-Mar-07 23:22 
Questionediting the dll file?!? Pin
thebirdman19849-Mar-07 1:45
thebirdman19849-Mar-07 1:45 
AnswerRe: editing the dll file?!? Pin
thebirdman19849-Mar-07 3:35
thebirdman19849-Mar-07 3:35 
AnswerRe: editing the dll file?!? Pin
Nicolas Wälti15-Mar-07 2:39
Nicolas Wälti15-Mar-07 2:39 
GeneralThe popup only fires in form load. Pin
astanton197821-Feb-07 2:06
astanton197821-Feb-07 2:06 
GeneralRe: The popup only fires in form load. Pin
astanton197821-Feb-07 4:05
astanton197821-Feb-07 4:05 
GeneralPort code to VS .NET Pin
utstudent26-Jan-07 16:37
utstudent26-Jan-07 16:37 
GeneralRe: Port code to VS .NET Pin
waltersenekal19-Feb-07 3:51
waltersenekal19-Feb-07 3:51 

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.