Search code examples
c#winformstextboxwindows-forms-designerform-control

C# Windows Form Application - value not printing in textbox for each time


Value not printing in textbox for each time.. Iam able to see last value only (10) in textbox.

  private void button1_Click(object sender, EventArgs e)
    {
      for(int i = 0; i<=10; i++)
       {
         textBox1.Text = i.ToString();
         Thread.Sleep(100);
       }
    }

Solution

  • In C# Window application, control values are render after event is executed.

    After your click event textbox is displaying last value that is updated.

    If you want to render text-box value during event execution.You have to call refresh method of text-box to render value.

    Use this.. You have to refresh textbox control.

     for (int i = 0; i <= 10; i++)
     {
        textBox1.Text = i.ToString();
        textBox1.Refresh();
        Thread.Sleep(100);
     }