2009-06-25 34 views
11

對於Windows窗體,有很多不錯的日期選擇器,但我還沒有找到任何時間只有採摘。.NET WinForms的時間選擇器?

有什麼建議嗎?


編輯

我想我應該更清楚。我正在談論一個更好看的時間選擇器。我們使用商業控制​​套件,默認時間選擇器看起來不合適,因爲它非常簡單。

+0

Windows窗體中的DateTimePicker可以僅使用CustomFormat屬性執行時間...您只是在尋找更具性感的控件嗎? – Brandon 2009-06-25 21:21:54

+0

是的,看起來更好。 – 2009-06-25 21:23:48

回答

14

的DatePicker有一個可以設置爲時間屬性的格式。 務必將ShowUpDown設置爲True。

Infragistics在Winforms中非常流行,並且可以選擇使用它的DateTimePicker。

...的MaskInput設置爲{}時間應該 得到你正在尋找的行爲。 如果僅設置FormatString 屬性,則僅當控件處於編輯模式 (當光標在控件中時)時,纔會顯示 。

http://forums.infragistics.com/forums/t/4172.aspx

17

你是說,相對於標準的Winforms DateTimePicker?

this.dateTimePicker1.CustomFormat = "hh:mm tt"; 
this.dateTimePicker1.Format = System.Windows.Forms.DateTimePickerFormat.Custom; 
this.dateTimePicker1.ShowUpDown = true; 

...

private void dateTimePicker1_ValueChanged(object sender, EventArgs e) 
{ 
    MessageBox.Show(dateTimePicker1.Value.TimeOfDay.ToString()); 
} 
7

只是爲了闡述Michael Petrotta's響應代碼

this.dateTimePicker1.CustomFormat = "hh:mm"; 

爲12小時的格式,其中如下面的代碼爲24小時格式

this.dateTimePicker1.CustomFormat = "HH:mm"; 
0
  1. 添加一個DateTimePicker控制
  2. 設置屬性 '格式',以 '時間'
  3. 設置屬性 '自定義格式' 爲 'HH:MM:SS'
  4. 設置屬性 'ShowUpDown' 爲 'True'

就是這樣