65.9K
CodeProject 正在变化。 阅读更多。
Home

GmailNotifierControl:一个类似 Gmail Notifier 的控件

starIconstarIconstarIconstarIcon
emptyStarIcon
starIcon

4.65/5 (11投票s)

2005年6月6日

CPOL

1分钟阅读

viewsIcon

107773

downloadIcon

2118

一个 Gmail 通知对话框控件,可用于任何应用程序,就像一个气泡提示一样。

Sample Image - GmailNotifierInfo.jpg

引言

我使用 Gmail 大约 8 个月了,我只能说 Gmail 团队做得很好。我也喜欢 Gmail Notifier 的行为方式……因此,我决定创建我自己的 Gmail Notifier 类似控件,以便在编写的应用程序中使用。

使用代码

GmailNotifierControl 由一个PictureBox、一个Label、一个或两个Timer(我本可以使用一个Timer,但代码就不会那么清晰)和一个 [ThatsItControl :) ] 组成。该控件公开了一些属性,这些属性在 VS IDE 的“其他...”部分下可见,以及一个方法,所有这些属性和方法如下所示

  • GmailImage:要在控件中显示的图像。
  • Info:要显示的文本。
  • Interval:在向上或向下移动控件之前要休眠的时间。
  • NotifyText:要在控件的通知图标中显示的文本。
  • Pitch:控件垂直移动的像素数(在 Y 轴上)。
  • TimeOut:信息可见的持续时间,在此持续时间之后控件将隐藏。
  • ShowInfo():显示控件中设置的信息。

代码本身很容易理解,请自行查看

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();
}

为了使属性在 IDE 中位于同一类别中,我使用了以下方法

   [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();
        }
    }

关注点

我尝试覆盖一些特定于窗体属性,例如不透明度,只是为了将它们放在“其他...”类别中,但没有成功。我也想完善此控件,因此任何贡献、任何建议都将受到欢迎。

© . All rights reserved.