winfrom,窗体抖动功能

2022-10-19,,,

 #region 方法一
Point first = this.Location;
for (int i = 0; i < 50; i++)
{
Application.DoEvents();
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(10);//当前线程再挂起10毫秒
this.Location = p;
System.Threading.Thread.Sleep(10);//当前线程再挂起10毫秒
Application.DoEvents(); }
this.Location = first; //将窗体还原为原来的位置 #endregion
#region 方法二
int x = this.Left;
int y = this.Top;
for (int i = 0; i < 3; i++)
{
this.Location = new Point(x - 3, y);
Thread.Sleep(10);//设置执行完上一步停留时间
this.Location = new Point(x - 3, y - 3);
Thread.Sleep(10);
this.Location = new Point(x, y - 3);
Thread.Sleep(10);
this.Location = new Point(x + 3, y - 3);
Thread.Sleep(10);
this.Location = new Point(x + 3, y);
Thread.Sleep(10);
this.Location = new Point(x + 3, y + 3);
Thread.Sleep(10);
this.Location = new Point(x, y + 3);
Thread.Sleep(10);
this.Location = new Point(x - 3, y + 3);
Thread.Sleep(10);
this.Location = new Point(x - 3, y);
Thread.Sleep(10);
this.Location = new Point(x, y);
}
#endregion

  

winfrom,窗体抖动功能的相关教程结束。

《winfrom,窗体抖动功能.doc》

下载本文的Word格式文档,以方便收藏与打印。