[Implement] 資訊通知上升視窗
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Text;
using System.Windows.Forms;
namespace UpgradeNotice
{
public partial class Form1 : Form
{
private int screenHeight;
private int screenWidth;
private int timeCount;
private int stopHightLocation;
public Form1()
{
InitializeComponent();
this.SetTopLevel(true);
this.screenWidth = Screen.PrimaryScreen.Bounds.Width;
this.screenHeight = Screen.PrimaryScreen.Bounds.Height;
this.Location = new System.Drawing.Point(screenWidth - Width - 5, screenHeight);
//設定是窗位置在右下角, 工具列上方
this.stopHightLocation = Screen.PrimaryScreen.Bounds.Height -
(Screen.PrimaryScreen.Bounds.Height - Screen.PrimaryScreen.WorkingArea.Height
+ this.Height);
}
private void Form1_Load(object sender, EventArgs e)
{
control_timer.Enabled = true;
close_timer.Enabled = true;
timeCount = 11;
close_timer.Interval = 1000;
//upgradeNoticeIsStart = true; //用來防止重複開啟視窗的flag
this.label1.Text = "Upgrade Notice";
this.label1.Left = this.Width / 2 - this.label1.Width / 2;
}
private void control_timer_Tick(object sender, EventArgs e)
{
if (screenHeight < stopHightLocation)
{
control_timer.Enabled = false;
return;
}
if ((screenHeight - 20) < stopHightLocation)
screenHeight = stopHightLocation;
else
screenHeight -= 20;
//this.Top = screenHeight;
this.Location = new System.Drawing.Point(screenWidth - Width - 5, screenHeight);
}
private void close_timer_Tick(object sender, EventArgs e)
{
timeCount -= 1;
if (timeCount == 0)
{
//upgradeNoticeIsStart = false; //用來防止重複開啟視窗的flag
this.Visible = false;
this.Dispose();
}
this.label2.Text = string.Format("於 {0} 秒後自動關閉", timeCount);
}
}
}
Result: