private void button2_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(10);
int y = random.Next(10);
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;
}
制作抖动窗体
最新推荐文章于 2024-12-15 18:28:03 发布
本文展示了一个使用C#编写的简单程序,该程序可以使窗体在屏幕上进行随机移动。通过随机数生成器,窗体根据偶数或奇数条件在水平和垂直方向上进行移动,同时利用线程睡眠来实现连续动画效果。
1496

被折叠的 条评论
为什么被折叠?



