Windows form: TextBox timer on button press

  • Thread starter Thread starter Yuvi105
  • Start date Start date
Y

Yuvi105

Guest
Hello,

I'm trying to run a very simple program that whenever i press a button i see a timer from 0 to 10 inside a text box,

but instead, i see an empty text box and after 10 seconds i see the number 10.


can someone suggest what am i missing here ?

Thanks !

Here is the code:


using System;
using System.Threading;
using System.Windows.Forms;


namespace WindowsFormsApp2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void textBox1_TextChanged(object sender, EventArgs e)
{

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

}

}

}

Continue reading...
 
Back
Top