【方法一】
第一步:winform項目創建完成后,添加一個窗口,命名為:Messages 。(加上最開始的Form1,一共為兩個窗口),雙擊主窗口進入后台代碼 。
第二步:在Messages 窗口中添加一個 timer 時鍾,修改一下屬性,將 Enabled 屬性改為 True ;Interval 屬性修改為1000(這是修改窗體彈出時間時的速度,)。
第三步:選擇事件按鈕,雙擊進入代碼界面,具體代碼如下:
private void timer1_Tick(object sender, EventArgs e)
{
timer1.Enabled = false;
for (int i = 0; i <= this.Height; i++)
{
Point p = new Point(this.Location.X, this.Location.Y + i);//彈出框向下移動消失
this.PointToScreen(p);//即時轉換成屏幕坐標
this.Location = p;// new Point(this.Location.X, this.Location.Y + 1);
System.Threading.Thread.Sleep(10);//下降速度調節,數字越小消失的速度越快,建議不大於10
}
this.Close();
this.Dispose();
}
第四步:返回主程序(Form1),雙擊窗體,添加代碼如下:
private void Form1_Load(object sender, EventArgs e)
{
Messages msg = new Messages();//將窗口Messages 實例化
Point p = new Point(Screen.PrimaryScreen.WorkingArea.Width - msg.Width, Screen.PrimaryScreen.WorkingArea.Height);
msg.PointToClient(p);
msg.Location = p;
msg.Show();
for (int i = 0; i < msg.Height; i++)
{
msg.Location = new Point(p.X, p.Y - i);
System.Threading.Thread.Sleep(1);//消息框彈出速度,數值越大越慢
}
}
