飞道的博客

C#实现窗体抖动

325人阅读  评论(0)
 
目录

窗体抖动封装一个类内,使用时直接调用即可

U层直接调用


P2P聊天的时候可以发送抖一抖,但是前提自己得先实现抖一抖,再通过网络发送吧。本文只是将基础的本地抖一抖实现了,局域网发送抖一抖,下一篇博客安排。

窗体抖动封装一个类内,使用时直接调用即可


  
  1. public class Shake
  2. {
  3. /// <summary>
  4. /// 震动方法
  5. /// </summary>
  6. /// <param name="form">窗体</param>
  7. public void Vibration(Form form)
  8. {
  9. Point pOld = form.Location; //原来的位置
  10. int radius = 3; //半径
  11. for ( int n = 0; n < 3; n++) //旋转圈数
  12. {
  13. //右半圆逆时针
  14. for ( int i = -radius; i <= radius; i++)
  15. {
  16. int x = Convert.ToInt32(Math.Sqrt(radius * radius - i * i));
  17. int y = -i;
  18. form.Location = new Point(pOld.X + x, pOld.Y + y);
  19. Thread.Sleep( 10);
  20. }
  21. //左半圆逆时针
  22. for ( int j = radius; j >= -radius; j--)
  23. {
  24. int x = -Convert.ToInt32(Math.Sqrt(radius * radius - j * j));
  25. int y = -j;
  26. form.Location = new Point(pOld.X + x, pOld.Y + y);
  27. Thread.Sleep( 10);
  28. }
  29. }
  30. //抖动完成,恢复原来位置
  31. form.Location = pOld;
  32. }
  33. }

U层直接调用


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

看效果:(录屏看着不太明显,真是观感还是挺明显的。嘿嘿嘿)

如果本篇博客对您有一定的帮助,大家记得留言+点赞哦。


转载:https://blog.csdn.net/promsing/article/details/109495040
查看评论
* 以上用户言论只代表其个人观点,不代表本网站的观点或立场