关于一个控件属性在函数的重复赋值
private void button1_Click(object sender, EventArgs e)
{int r=0;
label1.Visible = true;
label1.Text = "is runing ";
for(int i=0;i <100000;i++)
{r=r+i;}
lable1.Text= "is done ";
}
这样写的程序,到for循环结束,label1.text在form的显示不变化,还是is running,怎样改可以使label1.text在循环结束在form上显示为is done.
------解决方案--------------------private void button1_Click(object sender, EventArgs e)
{
int r = 0;
label1.Visible = true;
label1.Text = "is runing ";
for (int i = 0; i < 1000; i++)
{
r = r + i;
System.Threading.Thread.Sleep(10); // 假设是你的耗时语句
label1.Text = i.ToString();
Application.DoEvents();
}
label1.Text = "is done ";
}