Random ran = new Random((int)DateTime.Now.Ticks);
Point point = this.Location;
for (int i = 0; i < 37; i++)
{
this.Location = new Point(point.X + ran.Next(23) - 4, point.Y + ran.Next(23) - 4);
System.Threading.Thread.Sleep(15);
label1.Location = point;
// this.Location = point;
System.Threading.Thread.Sleep(15);
}
怎么改抖动label
假设label控件名为: label1。
可以如下:
Random ran = new Random((int)DateTime.Now.Ticks);
Point point = this.label1.Location;
for (int i = 0; i < 37; i++)
{
this.label1.Location = new Point(point.X + ran.Next(23) - 4, point.Y + ran.Next(23) - 4);
System.Threading.Thread.Sleep(15);
}
题目代码中this代表窗体。
修改后用this.label1找到窗体上对应的label控件。
其它代码不变就行。
Random ran = new Random((int)DateTime.Now.Ticks);
Point point = label1.Location;
for (int i = 0; i < 37; i++)
{
label1.Location = new Point(point.X + ran.Next(23) - 4, point.Y + ran.Next(23) - 4);
System.Threading.Thread.Sleep(15);
label1.Location = point;
System.Threading.Thread.Sleep(15);
}