|
C# 像 MSN 一样摇动窗口 (WinForm)
- <div>
- </div><div> int rand = 10;</div> private void button1_Click(object sender, EventArgs e)
- {
- int recordx = this.Left;
- int recordy = this.Top;
- Random random = new Random();
- for (int i = 0; i < 50; 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;
- }
- System.Threading.Thread.Sleep(1); // 增加睡眠值以获得慢速效果(禁用睡眠以获得更快的摇动)
- this.Left = recordx;
- this.Top = recordy;
- }
- }
-
Copy the Code
|
This post contains more resources
You have to Login for download or view attachment(s). No Account? Register
x
|