| |

VerySource

 Forgot password?
 Register
Search
View: 62|Reply: 1

C# 像 MSN 一样摇动窗口 (WinForm)

[Copy link]

1

Threads

1

Posts

14.00

Credits

Newbie

Rank: 1

Credits
14.00

 Denmark

Post time: 2025-2-7 22:51:44
| Show all posts |Read mode

C# 像 MSN 一样摇动窗口 (WinForm)

  1. <div>
  2. </div><div>        int rand = 10;</div>        private void button1_Click(object sender, EventArgs e)
  3.         {
  4.             int recordx = this.Left;
  5.             int recordy = this.Top;
  6.             Random random = new Random();
  7.             for (int i = 0; i < 50; i++) //增加值以获得更长的效果
  8.             {
  9.                 int x = random.Next(rand);
  10.                 int y = random.Next(rand);
  11.                 if (x % 2 == 0)
  12.                 {
  13.                     this.Left = this.Left + x;
  14.                 }
  15.                 else
  16.                 {
  17.                     this.Left = this.Left - x;
  18.                 }
  19.                 if (y % 2 == 0)
  20.                 {
  21.                     this.Top = this.Top + y;
  22.                 }
  23.                 else
  24.                 {
  25.                     this.Top = this.Top - y;
  26.                 }
  27.                 System.Threading.Thread.Sleep(1); // 增加睡眠值以获得慢速效果(禁用睡眠以获得更快的摇动)
  28.                 this.Left = recordx;
  29.                 this.Top = recordy;
  30.             }
  31.         }        
  32.         
Copy the Code


This post contains more resources

You have to Login for download or view attachment(s). No Account? Register

x
Reply

Use magic Report

11

Threads

69

Posts

4142.00

Credits

Administrator

Rank: 9Rank: 9Rank: 9

Credits
4142.00

 China

Post time: 2025-2-8 09:34:17
| Show all posts
感谢分享!
Losing My Religion.
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list