執行結果:
選擇前:
選擇後:
Code:
using System.Windows.Forms; namespace Post { public partial class Form1 : Form { /// <summary> /// DateTimePicker /// </summary> private DateTimePicker dtp = new DateTimePicker(); /// <summary> /// /// </summary> public Form1() { InitializeComponent(); InitUI(); } /// <summary> /// /// </summary> private void InitUI() { //格式為自訂 dtp.Format = DateTimePickerFormat.Custom; //初始化時為空 dtp.CustomFormat = " "; //當資料改變時在設定為正確格式 dtp.ValueChanged += (s, e) => { dtp.CustomFormat = "yyyy/dd/MM"; }; this.Controls.Add(dtp); } } }