C# realizes form jitter

 
table of Contents

The form jitter encapsulates in a class, it can be called directly when using

U layer direct call


You can send Shake and Shake during P2P chat, but you have to realize Shake and Shake before you send it over the network. This article only implements the basic local jitter, the local area network sends jitter, and the next blog arrangement.

The form jitter encapsulates in a class, it can be called directly when using

public class Shake
{
    /// <summary>
    /// 震动方法
    /// </summary>
    /// <param name="form">窗体</param>
    public void Vibration(Form form)
    {
        Point pOld = form.Location;//原来的位置
        int radius = 3;//半径
        for (int n = 0; n < 3; n++) //旋转圈数
        {
            //右半圆逆时针
            for (int i = -radius; i <= radius; i++)
            {
                 int x = Convert.ToInt32(Math.Sqrt(radius * radius - i * i));
                 int y = -i;

                 form.Location = new Point(pOld.X + x, pOld.Y + y);
                    Thread.Sleep(10);
            }
            //左半圆逆时针
            for (int j = radius; j >= -radius; j--)
            {
                 int x = -Convert.ToInt32(Math.Sqrt(radius * radius - j * j));
                 int y = -j;

                 form.Location = new Point(pOld.X + x, pOld.Y + y);
                 Thread.Sleep(10);
            }
        }
        //抖动完成,恢复原来位置
        form.Location = pOld;
    }

}

U layer direct call

Shake shake = new Shake();
shake.Vibration(this);//将窗体传进去

See the effect: (The recording is not very obvious, but the impression is quite obvious. Hehehe)

If this blog is helpful to you, please remember to leave a message + like it.

Guess you like

Origin blog.csdn.net/promsing/article/details/109495040