我希望在此代码中的任何步骤标签中显示该步骤的编号。
在我的代码中只显示标签中的最后一个数字!

我也 Label.Invalidate() 完成了,但不起作用。

    private void button1_Click(object sender, EventArgs e)
    {
        int i = 0;
        while (i<100)
        {
            i++;
            label1.Text = string.Format("Step is :{0}", i);
            System.Threading.Thread.Sleep(1000);
        }
   }

最佳答案

http://msdn.microsoft.com/en-us/library/system.windows.forms.control.update.aspx

设置文本后调用 Update ,它会帮助你。但当然你应该考虑后台线程。

label1.Text = string.Format("Step is :{0}", i);
label1.Update();
System.Threading.Thread.Sleep(1000);

关于c# - 在循环中的任何步骤中更改 Label.Text,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/4937838/

10-12 03:53
查看更多