我有这个代码,当我运行它时,它已移动但屏幕上有两个标签显示,一个没有移动,一个移动
public partial class Form1: Form
{
int x = 25, y = 1;
public Form1()
{
InitializeComponent();
}
private void timer1_Tick(object sender, EventArgs e)
{
label1.SetBounds(x, y, 255, 255);
x++;
if (x >= 800)
{
x = 1;
}
}
private void Form1_Load(object sender, EventArgs e)
{
label1.Text = "hii";
label1.Font = new Font(" ", 22, FontStyle.Bold);
timer1.Interval = 10;
timer1.Start();
}
}
您必须从工具箱添加一个标签到表单。在计时器设置中,新标签的界限也是这样的:
int x = 25, y = 1;
public Form1()
{
InitializeComponent();
}
private void timer1_Tick_1(object sender, EventArgs e)
{
label1.SetBounds(x, y, 255, 255);
label2.SetBounds(x, 100, 255, 255);
x++;
if (x >= 800)
{
x = 1;
}
}
private void Form1_Load_1(object sender, EventArgs e)
{
label1.Text = "hii";
label1.Font = new Font(" ", 22, FontStyle.Bold);
label2.Text = "hii2";
label2.Font = new Font(" ", 22, FontStyle.Bold);
timer1.Interval = 10;
timer1.Start();
}