在循环的任何步骤中更改Label.Text

use*_*695 3 c#

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

我也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);
        } 
   }
Run Code Online (Sandbox Code Playgroud)

Sno*_*ear 11

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);
Run Code Online (Sandbox Code Playgroud)