Repaint control in Timer event : Timer : GUI Windows Forms C# Examples


C# Examples » GUI Windows Forms » Timer »

 

Repaint control in Timer event








    
using  System;
using  System.Drawing;
using  System.Windows.Forms;

public  class  Timers  :  Form
{
    Label  lblTime;
    string  strFormat;

    public  Timers()
    {
        Size  =  new  Size(300,100);

        strFormat  =  "dddd,  MMMM  d,  yyyy    h:mm:ss  tt";

        lblTime  =  new  Label();
        lblTime.Parent  =  this;
        lblTime.Size  =  new  Size((int)(ClientSize.Width  *  .8),25);
        lblTime.Location  =  new  Point((int)(ClientSize.Width  *  .1),  
                                (int)(ClientSize.Height  *  .4));
        lblTime.BorderStyle  =  BorderStyle.FixedSingle;
        lblTime.Text  =  DateTime.Now.ToString(strFormat);
        lblTime.TextAlign  =  ContentAlignment.MiddleCenter;

        Timer  t  =  new  Timer();
        t.Interval  =  1000;        //  1  seconds
        t.Start();
        t.Tick  +=  new  EventHandler(t_Tick);
        
    }  

    static  void  Main()  
    {
        Application.Run(new  Timers());
    }

    private  void  t_Tick(object  sender,  EventArgs  e)
    {
        lblTime.Text  =  DateTime.Now.ToString(strFormat);
    }
}
    
   
  
   




HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo GUI Windows Forms
» Timer