窗体震动 C# (不使用Timer控件,控制窗体震动)
private static Point plocation = new Point();
public static void StartVibration(Form form)//Form 传入需要振动的窗体
{
plocation = form.Location;
for (int i = 1; i < 41; i++)//41,可以理解为震动的时间。注:时间需要被4取模=1
{
if (i < 41)
{
switch (i % 4)
{
case 0: form.Location = plocation;
break;
case 1: form.Location = new Point(plocation.X - 3, plocation.Y - 3);
break;
case 2: form.Location = new Point(plocation.X - 6, plocation.Y);
break;
case 3: form.Location = new Point(plocation.X - 3, plocation.Y + 3);
break;
}
}
System.Threading.Thread.Sleep(50);
}
}