用过QQ的窗口抖动功能吧。是不是觉得很神奇?很有意思?其实,仔细想想,使用的原理还是挺简单的:让窗口的位置不断快速地发生变化。

说出了原理,是不是一下恍然大悟?顿时理解了。我以前也想过如何实现这个功能,但是自己一点头绪都没有。现在终于知道了。原理如此简单。再神奇的事情,也有简单实现的方法。

 

private void btnShake_Click(object sender, EventArgs e)
        {
            Random ran = new Random((int)DateTime.Now.Ticks);
 
            Point point = this.Location;
 
            for (int i = 0; i < 40; i++)
            {
                this.Location = new Point(point.X + ran.Next(8) - 4, point.Y + ran.Next(8) - 4);
 
                System.Threading.Thread.Sleep(15);
 
                this.Location = point;
 
                System.Threading.Thread.Sleep(15);
            }
        }

 

 

相关文章:

  • 2021-09-15
  • 2021-11-03
  • 2022-01-23
  • 2021-07-02
  • 2021-06-18
  • 2022-12-23
  • 2022-12-23
  • 2021-11-14
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-02-17
  • 2022-12-23
  • 2022-12-23
  • 2021-07-30
  • 2022-12-23
相关资源
相似解决方案