Click here to Skip to main content
Licence CPOL
First Posted 23 Mar 2006
Views 163,782
Bookmarked 171 times

An Office 2003-like popup notifier

By | 23 Mar 2006 | Article
A nice little control to help the user notice you're trying to tell him something...

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:

Progressive appearance - transparency

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

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:

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.

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

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)

About the Author

Nicolas Wälti

Software Developer (Senior)

Switzerland Switzerland

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
NewsNew Version of this Control with many Bugs fixed (Link inside) PinmemberSimon B.4:54 3 Nov '11  
Questioncontrols property Pinmembersergio584:08 22 Jul '11  
GeneralShowing multiple popups at the same time. Pinmemberkdlc7:56 19 Jan '09  
GeneralUnable to close the popup with the close button!!! Pinmemberharvindersingh1153:04 1 Oct '08  
GeneralRe: Unable to close the popup with the close button!!! Pinmemberedzjx8:49 13 Feb '10  
GeneralRe: Unable to close the popup with the close button!!! Pinmemberjamslove4:29 16 Aug '10  
GeneralRe: Unable to close the popup with the close button!!! Pinmembernikoskritikos5:47 30 Aug '10  
QuestionHow to use this in a project C# Pinmemberharvindersingh1153:22 29 Sep '08  
AnswerRe: How to use this in a project C# Pinmemberharvindersingh1154:03 1 Oct '08  
GeneralRe: How to use this in a project C# Pinmemberlasai15:48 27 Jan '10  
GeneralExcellent Work........... PinmemberMember 40173816:14 19 Aug '08  
GeneralFrom right to left order Pinmemberammsamm0:40 22 Oct '07  
GeneralNew version anyone PinmemberNick Waelti23:21 25 Aug '07  
GeneralRe: New version anyone - I'd be glad Pinmembersemmel718:04 10 Oct '07  
GeneralRe: New version anyone PinmemberMember 13153206:22 23 Dec '07  
JokeRe: New version anyone Pinmembergaryjohn_20006:06 31 Dec '07  
NewsUnused Code Pinmemberpablleaf12:07 21 Jun '07  
NewsRedundant Line of Code Pinmemberpablleaf10:38 21 Jun '07  
GeneralSmall Doubt PinmemberGayuDams2:05 26 Apr '07  
GeneralOpacity Problem with multiple stacking popups Pinmemberfperugini10:18 22 Mar '07  
AnswerRe: Opacity Problem with multiple stacking popups Pinmemberfperugini4:33 23 Mar '07  
QuestionRe: Opacity Problem with multiple stacking popups PinmemberStyxke20:27 5 Apr '07  
AnswerRe: Opacity Problem with multiple stacking popups Pinmemberfperugini7:16 13 Apr '07  
GeneralMultiple Highlight Lines Pinmemberb00tleg9:38 22 Mar '07  
AnswerRe: Multiple Highlight Lines PinmemberNick Waelti22:34 22 Mar '07  
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
 

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

 
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.

If e.Parent.Form.MouseIsOnSecondTextLink Then
e.Parent.Form.Cursor = Cursors.Hand
e.Graphics.DrawString(e.Parent.SecondContentText, New Font(SystemFonts.DialogFont, FontStyle.Underline), New SolidBrush(Color.Black), e.Parent.Form.RectSecondText)
Else
e.Parent.Form.Cursor = Cursors.Default
e.Graphics.DrawString(e.Parent.SecondContentText, New Font(SystemFonts.DialogFont, FontStyle.Regular), New SolidBrush(Color.Black), e.Parent.Form.SecondRectText)
End If

 
then in PopupNotifier.vb:

Private sText2 As String
_
Property SecondContentText() As String
Get
Return sText2
End Get
Set(ByVal value As String)
sText2 = value
 
End Set
End Property

And then for PopupNotifierForm.vb:
 

Public ReadOnly Property SecondRectText() As RectangleF
Get
If Not Parent.Image Is Nothing Then
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)
Else
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)
End If
End Get
End Property

Then alors in the mouse_move event

If SecondRectText.Contains(e.X, e.Y) Then
bMouseOnLink2 = True
Else
bMouseOnLink2 = False
End If

 
And that should pretty much do the trick Smile | :)

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.

Permalink | Advertise | Privacy | Mobile
Web03 | 2.5.120529.1 | Last Updated 23 Mar 2006
Article Copyright 2006 by Nicolas Wälti
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid