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


 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;   //将窗体还原为原来的位置    

        }
    }
}
 

原文地址:https://www.cnblogs.com/yja9010/p/3178816.html