HOW TO:在 .NET Compact Framework 中使用 DateTimePicker 類別
更新:2007 年 11 月
.NET Compact Framework 版支援 DateTimePicker 類別,但只具有下列成員:
CalendarFont 屬性
CustomFormat 屬性
Format 屬性。.NET Compact Framework 支援 DateTimePickerFormat 列舉型別的所有值。
MaxDate 屬性
MinDate 屬性
ShowUpDown 屬性
ValueChanged 事件
請注意,因為提供了 OnValueChanged,所以衍生類別可以使用這個方法,而不必連接事件處理常式委派。如需使用委派的詳細資訊,請參閱引發事件。
注意事項: |
---|
Smartphone 的 DateTimePicker 可在 Smartphone 的 Windows Mobile 5.0 版軟體中使用。Smartphone 上的控制項沒有上下按鈕選取器,因為是利用巡覽鍵來選取值。 |
範例
以下程式碼範例會說明如何設定 .NET Compact Framework 中的 DateTimePicker 控制項。
Private Sub SetupDateTimePicker()
' Set the MinDate and MaxDate.
DateTimePicker1.MinDate = new DateTime(1985, 6, 12)
DateTimePicker1.MaxDate = DateTime.Today
'Set the format.
DateTimePicker1.Format = DateTimePickerFormat.Short
' Define a custom format.
DateTimePicker1.CustomFormat = "MMMM dd, yyyy - dddd"
' If you want to use the custom format, change
' DateTimePickerFormat.Short to DateTimePickerFormat.Custom.
' Display the control with the up-down selector.
DateTimePicker1.ShowUpDown = True
End Sub
Private Sub DateTimePicker1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DateTimePicker1.ValueChanged
' Respond to changes, such as using
' the updated value in your application.
End Sub
private void SetupDateTimePicker()
{
// Set the MinDate and MaxDate.
dateTimePicker1.MinDate = new DateTime(1985, 6, 12);
dateTimePicker1.MaxDate = DateTime.Today;
// Set the format.
dateTimePicker1.Format = DateTimePickerFormat.Short;
// Define a custom format.
dateTimePicker1.CustomFormat = "MMMM dd, yyyy - dddd";
// If you want to use the custom format, change
// DateTimePickerFormat.Short to DateTimePickerFormat.Custom.
// Display the control with the up-down selector.
dateTimePicker1.ShowUpDown = true;
}
private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
{
// Respond to changes, such as using
// the updated value in your application.
}
編譯程式碼
這個範例需要下列命名空間的參考: