private void InitializeTimer()
{
// Call this procedure when the application starts.
// Set to 1 second.
timer1.Interval = 1000;
timer1.Tick += new EventHandler(timer1_Tick); // Enable timer.
timer1.Enabled = true;
}
private void timer1_Tick(object sender, EventArgs e)
{
label4.Text = System.DateTime.Now.ToString("H:M");
}
按我的设想应该是label4显示当前时间。
结果label4根本不变。
private void label4_Click(object sender, EventArgs e)
{
label4.Text = System.DateTime.Now.ToString("H:M");
}
我又写了这样一句,结果一点它就显示了。
求教哪里出问题了
获取时间的问题你试试这个获取时间
在时间Tick事件里面每次加一秒就行了
2:楼主完全也可以手动直接设置以下属性,VS会自动处理(Form2.Designer.cs) this.timer1.Enabled = true;
this.timer1.Interval = 1000;
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
{
label4.Text = System.DateTime.Now.ToString("H:M");
}
还用得着这个????