winfrom窗体抖动功能

 #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

  

posted @ 2022-09-02 14:09  fulllove  阅读(62)  评论(0)    收藏  举报