您的位置:首页 > 编程语言

Winform实现窗体抖动的效果代码

2010-11-09 06:38 453 查看
Winform实现窗体抖动的效果代码,我们都知道,在目前的即时通讯工具中都有窗体抖动的功能,这也是为了及时通知对方而设立的功能,今天我们就用Winform的C#版来实现窗体拌动的功能!

思路:间隔一定时间,改变窗体的位置,必须是围绕起始位置改变窗体位置,否则就成窗体移动了。

代码如下:

using System;
using System.Drawing;
using System.Windows.Forms;

namespace twitter
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{

//实现窗体抖动的效果
Point first =this .Location;
for (int i = 0; i < 8; i++)
{
Random ran = new Random();
Point p = new Point(this.Location.X + ran.Next(10) - 4, this.Location.Y +
ran.Next(10) - 4);
System.Threading.Thread.Sleep(15);//当前线程挂起15毫秒
this.Location = p;
System.Threading.Thread.Sleep(15);//当前线程再挂起15毫秒

}
this.Location = first; //将窗体还原为原来的位置

}
}
}

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: