title: Run a Digital Clock on your WinForm
body: <p>Hi I have to design a Windows Form which has a simple textbox. The textbox contains a timer like text (00:00 format).</p>
  
  <p>I want to refresh the page every second and make the content of the textbox change accordingly. (Just like a digital clock, running for say, one hour!).</p>
  
  <p>I figured out I need to use the <code>System.Windows.Forms.Timer</code> class and I have dropped a <code>Timer</code> item from the ToolBox to my Form.</p>
  
  <p>What next... Do I need to use <code>Thread.Sleep(1000)</code> function.. any ideas ?</p>
  
  <p>Here is the code-piece i have been trying. I know where it goes wrong in the program, and the <code>thread.sleep()</code> part even makes it worse for my code to Run. I tried the Timer stuff in the ToolBox, but could not get through.(When i run the code, it compiles successfully and then the application freezes for one Hour due to the dirty For-Loops) Help !!</p>
  
  <pre><code>  public  partial class Form1 : Form
  {
      Button b = new Button();
      TextBox tb = new TextBox();
      //System.Windows.Forms.Timer timer1 = new System.Windows.Forms.Timer();
  
      public Form1()
      {
          b.Click += new EventHandler(b_click);
          b.Text = "START";
          tb.Text = "00 : 00";
          //timer1.Enabled = true;
          //timer1.Interval = 1000;
          tb.Location = new Point(100, 100);
          this.Controls.Add(tb);
          this.Controls.Add(b);
          InitializeComponent();
      }
  
      private void refreshTimer_Tick()
      {
  
         for (int i = 0; i &lt; 60; i++)
          {
              for (int j = 0; j &lt; 60; j++)
              {
                  Thread.Sleep(500);
                  string TempTime = string.Format("{0:00} : {1:00}",i,j);
                  tb.Text = TempTime;                    
                  Thread.Sleep(500);
  
              }
          }
      }
      public void b_click(object sender, EventArgs e)
      {
          refreshTimer_Tick();
  
      }
  }
  </code></pre>