NET Compact Framework 2.0 版支援 DateTimePicker 類,但僅支援下列成員:
- CalendarFont 屬性。
- CustomFormat 屬性。
- Format 屬性。.NET Compact Framework 支援 DateTimePickerFormat 枚舉的所有值。
- MaxDate 屬性。
- MinDate 屬性。
- ShowUpDown 屬性。
- ValueChanged 事件。
- OnValueChanged 方法。
注意,由于提供了 OnValueChanged,是以派生類可以在不連接配接事件處理程式委托的情況下使用此方法。有關使用委托的更多資訊,請參見引發事件。
注意 |
---|
Smartphone 的 DateTimePicker 将可以在用于 Smartphone 的 Windows Mobile 5.0 版軟體中使用。請注意,由于使用導航鍵選擇值,是以 Smartphone 上的控件沒有上/下選擇器。 |
示例
下面的代碼示例示範了如何在 .NET Compact Framework 中配置 DateTimePicker 控件。
Visual Basic
複制代碼
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
C#
複制代碼
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.
}
編譯代碼
此示例需要引用下面的命名空間:
- System
- System.Windows.Forms