[英]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.