[英]How to get selected date into the text box from the calendar-that popup from Icon?
[英]DateTimePicker: How will I handle if the user clicked/selected date in the popup calendar or not?
我注意到C#的DateTimePicker在更改月份或年份时会自动更改日期。 因此,我要做的是重写ValueChanged,并且仅在引发CloseUp事件时才触发它。
现在的问题是,如果用户实际上在日历中选择了日期,或者用户在控件外部单击,则需要一个事件。
你能帮我吗? 谢谢 :)
在派生类中,重写的OnValueChanged
方法很适合我。
public class MyDateTimePicker : DateTimePicker
{
// ... some stuff
protected override void OnValueChanged(EventArgs eventargs)
{
System.Diagnostics.Debug.Write("Clicked - ");
System.Diagnostics.Debug.WriteLine(this.Value);
base.OnValueChanged(eventargs);
}
protected override void OnCloseUp(EventArgs eventargs)
{
System.Diagnostics.Debug.Write("Closed - ");
System.Diagnostics.Debug.WriteLine(this.Value);
base.OnCloseUp(eventargs);
}
// some more stuff ...
}
在派生类中,重写的OnCloseUp
方法起作用是因为在重置日期时间控件时,不会触发ValueChange
事件,因此CloseUp
事件派上了用场。
void ProductionDateSchdl_CloseUp(object sender, EventArgs e)
{
this.ProductionDateSchdl.CustomFormat = "MM/dd/yyyy";
ProductionDate = Convert.ToDateTime(this.ProductionDateSchdl.Value);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.