65.9K
CodeProject is changing. Read more.
Home

GmailNotifierControl: A Gmail Notifier like control

starIconstarIconstarIconstarIcon
emptyStarIcon
starIcon

4.65/5 (11 votes)

Jun 6, 2005

CPOL

1 min read

viewsIcon

106480

downloadIcon

2118

A Gmail Notifier dialog control, to use with any app, just like a baloon tooltip.

Sample Image - GmailNotifierInfo.jpg

Introduction

I've been using Gmail for something like 8 months, and all I can say is that the Gmail team did a good work. I also liked the Gmail Notifier, the way it acts... I decided thus to create my own Gmail Notifier like control, so as to use it in apps I write.

Using the code

The GmailNotifierControl is made of a picture box, a label, one or two timers (I could have used only one but the code wouldn't have been that clear) and a [ThatsItControl :)]. The control exposes some properties visible under the Misc... section in the VS IDE, and a method, all of which are listed below:

  • GmailImage: The image to show in the control.
  • Info: The text to display.
  • Interval: The time to sleep before moving the control up or down.
  • NotifyText: The text to display in the notify icon of the control.
  • Pitch: The number of pixels by which the control is moved vertically (in the Y axis).
  • TimeOut: The duration of visibility of the info, after that duration the control hides.
  • ShowInfo(): Shows the info set in the control.

The code itself is easy to understand, just see by yourself:

private void tmrMove_Tick(object sender, System.EventArgs e)
{
    int nTaskBarHeight = Screen.PrimaryScreen.Bounds.Bottom - 
                         Screen.PrimaryScreen.WorkingArea.Bottom;
    if(!bHide) //Show the Info Box
    {
        this.Show();
        if ( this.Top > Screen.PrimaryScreen.Bounds.Bottom - 
           (this.Height + nTaskBarHeight )) //screen limit - TaskBarSize
        {    
            this.TopMost = false;
            this.Top -= nPitch;
            this.Refresh();
            bFinished = false;
        }
        else 
        {
            this.TopMost = true;
            bFinished = true;
            this.Refresh();
            bHide = true;
        }
    }
    else if (!bFinished) //Hide It
    {
        if ( this.Top < Screen.PrimaryScreen.Bounds.Bottom )
        {    
            this.TopMost = false;
            this.Top += nPitch;
            this.Refresh();
            bFinished = false;
        }
        else 
        {
            this.TopMost = true;
            this.Hide();
            bFinished = true;
            bHide = false;
        }
    }
    if (bFinished)
        tmrMove.Stop();
    if (bHide && bFinished)
        tmrEnd.Start();
}

In order to have the properties in the same category in the IDE, I used this:

   [Category("Misc..."), 
    Description("The TimeOut in milliseconds of GmailNotifierControl Info")]
    public int TimeOut
    {
        get
        {
        return this.nTimeOut / 1000;
        }
        set
        {
        this.nTimeOut = value * 1000;
        this.tmrEnd.Interval = value * 1000;
        }
    }
    
    [Category("Misc..."), 
     Description("The text to show in the GmailNotifierControl")]
    public string Info
    {
        get
        {
        return this.strInfo;
        }
        set
        {
        this.lblInfo.Text = value;
        this.strInfo = value;
        this.Refresh();
        }
    }

Points of Interest

I have tried to override some form specific properties like opacity, just to get them together in the Misc... category but couldn't. I would also like to refine this control, so any contribution, any suggestions, would be welcome.