做一个简单的C#窗口抖动,仿QQ窗口抖动效果!
首先,在窗口中添加一个按钮:
C#窗口抖动图
在按钮中输入一下代码:
即:
- int recordx = this.Left;
- int recordy = this.Top;
- Random random = new Random();
- for (int i = 0; i < 150; i++)
- {
- int x = random.Next(rand);
- int y = random.Next(rand);
- if (x % 2 == 0)
- {
- this.Left = this.Left + x;
- }
- else
- {
- this.Left = this.Left - x;
- }
- if (y % 2 == 0)
- {
- this.Top = this.Top + y;
- }
- else
- {
- this.Top = this.Top - y;
- }
- this.Left = recordx;
- this.Top = recordy;
- }
这样,一个简单的C#窗口抖动效果就实现了!
【编辑推荐】