单击事件发生时如何在datetimepicker上绑定按钮单击事件 [英] How to bound button click event on datetimepicker when was click event happend
问题描述
Hello Guys我有按钮点击事件(女巫正在使用计时器),我有DatetimePicker,你可以帮我如何在日期时间选择器上点击按钮时约束日期和时间
Hello Guys I have button click event (witch is working on timer) and i have DatetimePicker and can you help me how i can bound date and time when button was clicked on datetime picker
private void timer1_Tick(object sender, EventArgs e)
{ button1_Click(sender, e);
button2_Click_1(sender, e);
second = second + 1;
}
这是我的日期时间选择器格式
什么我试过了:
public Form1()
{
InitializeComponent();
dateTimePicker1.Format = DateTimePickerFormat.Long;
dateTimePicker1.ShowUpDown = false;
}
//这里是日期时间选择器
i在这里尝试获取Button事件但是我不能错过我beaocuse他没有看到这个事件
this is my datetime picker format
What I have tried:
public Form1()
{
InitializeComponent();
dateTimePicker1.Format = DateTimePickerFormat.Long;
dateTimePicker1.ShowUpDown = false;
}
//here is datetime picker
i tried here to Get the Button event but i can't erroring me beaocuse he don't see this event
推荐答案
计时器不是用于获取当前时间。它用于在给定时间(或一次又一次地以给定间隔)触发动作。如果我正确地读了你的问题,你不需要计时器。
如果你想设置 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;
}
这篇关于单击事件发生时如何在datetimepicker上绑定按钮单击事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!