且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

单击事件发生时如何在datetimepicker上绑定按钮单击事件

更新时间:2023-09-29 18:47:52

计时器不是用于获取当前时间。它用于在给定时间(或一次又一次地以给定间隔)触发动作。如果我正确地读了你的问题,你不需要计时器。



如果你想设置 DateTimePicker 到按下按钮的时间,设置其Value 属性:
The timer is not for getting the current time. It is for triggering actions at a given time (or at given intervals again and again). If I read your question correctly, you don't need the timer.

If you want to set the DateTimePicker to the time the button was pressed, set its Value property:
void button1_Click(object sender, EventArgs e)
{
    dateTimePicker1.Value = DateTime.Now;
}