Skip to main content
Email Password   helpLost your password?

Introduction

Since I am learning C#, I thought it would be helpful for me to port my C++ CTaskbarNotifier class (http://www.codeproject.com/dialog/TaskbarNotifier.asp[ ^])

As a result, I coded a MSN Messenger-like skinnable popup, with a close button which looks almost like Microsoft's one (with the associated skin).

The TaskbarNotifier class inherits from System.Windows.Forms.Form and adds a few methods to it.

Features

The MSN messenger like popup supports:

Compatibility

This class is stand alone and doesn't need any particular libraries except .NET default ones. It runs in managed code and hence should be portable.

How to use the class

You can play with a few properties:

Class documentation

Methods

void Show(string strTitle, string strContent, int nTimeToShow, 
                                            int nTimeToStay, int nTimeToHide)

Displays the popup for a certain amount of time.

Parameters

void Hide()

Forces the popup to hide.

void SetBackgroundBitmap(string strFilename, Color transparencyColor)

Sets the background bitmap and its transparency color.

Parameters

void SetBackgroundBitmap(Image image, Color transparencyColor)

Sets the background bitmap and its transparency color.

Parameters

  • image: Background bitmap
  • transparencyColor: Color of the bitmap which won't be visible
    void SetCloseBitmap(string strFilename, 
                Color transparencyColor, Point position)

    Sets the 3-State close button bitmap, its transparency color and its coordinates.

    Parameters

    void SetCloseBitmap(Image image, Color transparencyColor, Point position)

    Sets the 3-State close button bitmap, its transparency color and its coordinates.

    Parameters

    Properties

    string TitleText (get/set)
    string ContentText (get/set)
    TaskbarStates TaskbarState (get)
    Color NormalTitleColor (get/set)
    Color HoverTitleColor (get/set)
    Color NormalContentColor (get/set)
    Color HoverContentColor (get/set)
    Font NormalTitleFont (get/set)
    Font HoverTitleFont (get/set)
    Font NormalContentFont (get/set)
    Font HoverContentFont (get/set)
    Rectangle TitleRectangle (get/set) //must be defined before calling show())
    
    Rectangle ContentRectangle (get/set) //must be defined before calling show())
    
    bool TitleClickable (get/set) (default = false);
    bool ContentClickable (get/set) (default = true);
    bool CloseClickable (get/set) (default = true);
    bool EnableSelectionRectangle (get/set) (default = true);

    Events

    event EventHandler CloseClick
    event EventHandler TitleClick
    event EventHandler ContentClick

    Technical issues

    The popup is skinned using a region generated dynamically from a bitmap and a transparency color:

    protected Region BitmapToRegion(Bitmap bitmap, Color transparencyColor)
    {
        if (bitmap == null)
            throw new ArgumentNullException("Bitmap", "Bitmap cannot be null!");
    
        int height = bitmap.Height;
        int width = bitmap.Width;
    
        GraphicsPath path = new GraphicsPath();
    
        for (int j=0; j<height; j++ )
            for (int i=0; i<width; i++)
            {
                if (bitmap.GetPixel(i, j) == transparencyColor)
                    continue;
    
                int x0 = i;
    
                while ((i < width) && 
                        (bitmap.GetPixel(i, j) != transparencyColor))
                    i++;
    
                path.AddRectangle(new Rectangle(x0, j, i-x0, 1));
            }
    
        Region region = new Region(path);
        path.Dispose();
        return region;
    }

    The refresh() of the popup is done using the double buffering technique to avoid flickering:

    protected override void OnPaintBackground(PaintEventArgs pea)
    {
        Graphics grfx = pea.Graphics;
        grfx.PageUnit = GraphicsUnit.Pixel;
    
        Graphics offScreenGraphics;
        Bitmap offscreenBitmap;
    
        offscreenBitmap = new Bitmap(BackgroundBitmap.Width, 
                                    BackgroundBitmap.Height);
        offScreenGraphics = Graphics.FromImage(offscreenBitmap);
    
        if (BackgroundBitmap != null)
        {
            offScreenGraphics.DrawImage(BackgroundBitmap, 
                0, 0, BackgroundBitmap.Width, BackgroundBitmap.Height);
        }
    
        DrawCloseButton(offScreenGraphics);
        DrawText(offScreenGraphics);
    
        grfx.DrawImage(offscreenBitmap, 0, 0);
    }

    Bugs/Limitations

    Since I wanted to keep only managed code, I used the Screen.GetWorkingArea(WorkAreaRectangle) function instead of using unmanaged code to get the taskbar position. As a result, I made the popup always appear at the bottom of WorkAreaRectangle whichever position the taskbar has.

    I didn't find any C# managed equivalent to the Win32 function ShowWindow(SW_SHOWNOACTIVATE) to make the popup, not steal the focus of the active window.

    Updates

    Conclusion

    I hope this code will be useful to you. If you have suggestions to enhance this class functionalities, please post a comment.

  • You must Sign In to use this message board.
     
     
    Per page   
     FirstPrevNext
    QuestionText Alignment of strContent Pin
    flaurita
    6:04 19 Nov '09  
    GeneralEvents won't fire Pin
    nowh3r32h1d3
    0:03 30 Oct '09  
    GeneralNotifier do not appear if client code is on a class library o console project Pin
    Francesco Randazzo
    6:08 14 Oct '09  
    Generalproperty no found "Skin.bmp" VC# Express Pin
    Daniel Garzon
    13:52 7 Oct '09  
    QuestionProblem with Win7 Pin
    bzyy11
    0:26 15 Sep '09  
    AnswerRe: Problem with Win7 Pin
    bzyy11
    2:20 15 Sep '09  
    GeneralRe: Problem with Win7 Pin
    see_seA
    6:08 5 Oct '09  
    GeneralProblems with Vista? Pin
    LegoMindstorms
    7:39 25 Aug '09  
    GeneralIs there a way to make the edges smooth Pin
    Muhammad Ahmed
    7:16 10 Aug '09  
    GeneralLicense Pin
    tknman0700
    12:13 26 Jul '09  
    GeneralThanx! Pin
    janniebun
    7:31 20 Jul '09  
    GeneralC++ version and messenger.zip Pin
    tipiak07
    9:55 28 Jun '09  
    GeneralHow to make the pop up a scheduled one Pin
    Yeshwanthhv
    0:28 16 Jun '09  
    GeneralVery nice example Pin
    Member 2234401
    11:53 29 May '09  
    GeneralReally terrific, Thanks! Pin
    Jamie Simon
    8:26 24 Apr '09  
    Generalmissing resource file Pin
    ottilia
    6:47 4 Apr '09  
    GeneralASP.NET Pin
    Siphiwe
    2:37 25 Mar '09  
    GeneralVB 2005 skin.bmp Pin
    roscael
    18:16 25 Feb '09  
    GeneralRe: VB 2005 skin.bmp Pin
    klemmax
    5:36 26 Feb '09  
    GeneralRe: VB 2005 skin.bmp Pin
    roscael
    7:26 26 Feb '09  
    GeneralFocus stealing woes Pin
    r_hyde
    1:54 24 Feb '09  
    GeneralRe: Focus stealing woes [modified] Pin
    r_hyde
    17:20 25 Feb '09  
    GeneralRe: Focus stealing woes Pin
    Josh Powers
    9:04 27 Feb '09  
    GeneralRe: Focus stealing woes [modified] Pin
    r_hyde
    17:25 28 Feb '09  
    QuestionUse in VB.NET and Visual Studio 2008 Pin
    itmanager8815
    13:38 16 Feb '09  


    Last Updated 30 Mar 2003 | Advertise | Privacy | Terms of Use | Copyright © CodeProject, 1999-2009