C# Winform右下角弹窗方式

【方法一】

第一步: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);//消息框弹出速度,数值越大越慢
}
}

 

posted @ 2018-06-23 01:08  顾德博  阅读(4889)  评论(1编辑  收藏  举报