.Notifier
介绍 本文提供了一个popup-less通知窗口,并节省了用户从“Click-on-the-OK-button-to-continue”的痛苦。 背景 当使用Microsoft Outlook,你遇到一个邮件通知窗口慢慢出现,消失了。但是,当你把鼠标在窗口,它变得不透明,然后再次鼠标,它消失了,这个过程仍在继续。所以,最终,它逐渐消退或你忽略了窗口,或者你关闭它或者你点击它阅读邮件。本文描述了如何使用c#构建这样的一个窗口。 的逻辑 下面是步骤: 最初使透明度级别0。显示窗口。开始显示定时器T1。逐步提高透明度的T1,直到达到最大水平1.0。停止定时器T1。启动隐藏计时器T2。降低不透明度水平T2,直到达到的最低水平0.01。停止计时器T2。干净的消息。关闭窗口。 使用的代码 基本类,实现了逻辑是KNotifio。 隐藏通知窗口计时器 隐藏的计时器事件如下: 隐藏,复制Code
privatevoid tmrHide_Tick(object sender, EventArgs e) { //Decrease the opacity level until its greater than zero if (this.Opacity > 0.00) { this.Opacity -= 0.01; } else { //Window has gone completely transparent tmrHide.Stop(); //Stop the timer CloseWnd(); //Close window } }
显示通知窗口计时器 显示计时器事件如下: 隐藏,复制Code
private void tmrShow_Tick(object sender, EventArgs e) { //Increase opacity until it reaches maximum if (this.Opacity < 0.99) { this.Opacity += 0.01; } else { //Window already opaque tmrShow.Stop(); //Let's stop the timer tmrHide.Start(); //Start hiding the window } }
关闭通知窗口 下面是如何关闭窗口: 隐藏,复制Code
private void CloseWnd() { try { //Stop timers g_Fio.tmrHide.Stop(); g_Fio.tmrShow.Stop(); g_Fio.Close(); //Close the form m_strPreviousMessage = string.Empty; //Clean message } catch (Exception exec) { } }
窗口如何显示 隐藏,复制Code
public static void Show(string strMessage, i nShowTime, int nHideTime) { //Set the time it should take to show the window m_nShowTime = nShowTime - 5; //Set the time it would take to hide the window m_nHideTime = nHideTime; Show(strMessage); }
Show()方法 隐藏,复制Code
public static void Show(string strMessage) { try { if (m_strPreviousMessage == strMessage) return; else m_strPreviousMessage = strMessage; KNotifio theNotifio = new KNotifio(); g_Fio = theNotifio; theNotifio.txtMessage.Text = strMessage; theNotifio.Show(); theNotifio.panel1.Focus(); } catch (Exception exc) { ; } }
构造函数初始化/ 隐藏,复制Code
public KNotifio() { InitializeComponent(); tmrHide.Interval = m_nHideTime; //Set timers tmrShow.Interval = m_nShowTime; try { //Set round rects } catch (Exception exc) { } //Move window close to system tray (above the clock) Location = new Point(Screen.PrimaryScreen.Bounds.Width - this.Width, Screen.PrimaryScreen.Bounds.Height - this.Height - 50); }
圆角 我们称之为一个API圆的角落。 隐藏,复制Code
/// <spanclass="code-SummaryComment"><summary></span> /// Provides MS Outlook styled dynamic notification window /// <spanclass="code-SummaryComment"></summary></span> public partial class KNotifio : Form { //Need to make our window a bit rounded. [DllImport("Gdi32.dll", EntryPoint = "CreateRoundRectRgn")] private static extern IntPtr CreateRoundRectRgn ( int nLeftRect, // x-coordinate of upper-left corner int nTopRect, // y-coordinate of upper-left corner int nRightRect, // x-coordinate of lower-right corner int nBottomRect, // y-coordinate of lower-right corner int nWidthEllipse, // height of ellipse int nHeightEllipse // width of ellipse ); ....
的兴趣点 用户可以设置特定的窗口动画。同样的,例如,消息类型是至关重要的信息,和盒子可以眨眼,等等。控制可以使更多的动画,用户集中,我们只需要设置AnimationTypes。警告标签。 本文转载于:http://www.diyabc.com/frontweb/news7275.html