使用過MSN的朋友應該都知道, 當有新訊息時, 右下角會跳出一個提示小方框

這邊用簡單的程式碼來達到類似的效果, 當然這只是陽春版, 只有簡單的訊息提示而已

實作效果: 訊息方框由右下角緩慢上升 > 靜止數秒 > 緩慢下降 > 關閉提示視窗

程式碼片段如下:


// 建立訊息提示方框物件
public MsgNotify(String sender)
{
    InitializeComponent();
    this.m_message = sender;
    this.ShowInTaskbar = false;
    this.tNotifierUP.Tick += new EventHandler(positionUP);
    this.tNotifierStall.Tick += new EventHandler(stall);
    this.tNotifierDown.Tick += new EventHandler(positionDN);
    this.tNotifierClose.Tick += new EventHandler(closeNotifier);
    this.tNotifierUP.Start();
}

// 提示框上升
private void positionUP(Object myObject, EventArgs myEventArgs)
{
    if (this.Location.Y <= SystemInformation.WorkingArea.Bottom - this.Height)
    {
        this.tNotifierUP.Stop();
        this.tNotifierStall.Start();
    }
    this.Location = new Point(this.Location.X, this.Location.Y - 5);
}

// 提示框下降

private void positionDN(Object myObject, EventArgs myEventArgs)
{
    if (this.Location.Y >= SystemInformation.WorkingArea.Bottom)
    {
        this.tNotifierDown.Stop();
        this.tNotifierClose.Start();
    }
    this.Location = new Point(this.Location.X, this.Location.Y + 5);
}

// 提示框暫留
private void stall(Object myObject, EventArgs myEventArgs)
{
    this.tNotifierDown.Start();
}

private void closeNotifier(Object myObject, EventArgs myEventArgs)
{
    this.Close();
}

// 滑鼠事件
private void MsgNotify_MouseEnter(object sender, EventArgs e)
{
    this.Location = new Point(SystemInformation.WorkingArea.Right - this.Width,
                                             SystemInformation.WorkingArea.Bottom - this.Height);
    this.tNotifierStall.Stop();
    this.tNotifierDown.Stop();
    this.tNotifierClose.Stop();
}

// 滑鼠事件
private void MsgNotify_MouseLeave(object sender, EventArgs e)
{
    this.tNotifierStall.Start();
}

這是最最陽春的提示效果, 程式碼不難, 細節就不多做註解囉

arrow
arrow
    全站熱搜

    沒 發表在 痞客邦 留言(3) 人氣()