Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change Label.Text in any step in the loop

Tags:

c#

I want in this code in the any step label show the Number of that step. In the my code just show last number in the label!

I also Label.Invalidate() the done, but do not work.

    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);
        } 
   }
like image 255
user608695 Avatar asked Sep 18 '25 14:09

user608695


1 Answers

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

Invoke Update after setting text, it will help you. But of course you should consider background threads.

label1.Text = string.Format("Step is :{0}", i);
label1.Update();
System.Threading.Thread.Sleep(1000);
like image 163
Snowbear Avatar answered Sep 21 '25 05:09

Snowbear