winform real-time clock function

// main analog clock beat per second

// First, write a method to get real-time

private void GetDateTimeTick(object sender, EventArgs e)
{
textBox1.Text = DateTime.Now.ToString("HH:mm:ss");
}

// define a timer control, use a major event Tick control, set up the method once every 1000 milliseconds to call the above, in order to achieve clock function

Timer dateTimer = new Timer();
dateTimer.Tick += GetDateTimeTick;
dateTimer.Interval = 1000;
dateTimer.Start();

Guess you like

Origin www.cnblogs.com/misssds/p/11993534.html