如何:在 .NET Compact Framework 中使用 DateTimePicker 类

更新:2007 年 11 月

.NET Compact Framework 支持 DateTimePicker 类,但仅支持下列成员:

注意,由于提供了 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.

}

编译代码

此示例需要引用下面的命名空间:

请参见

其他资源

.NET Compact Framework 中的 Windows 窗体控件

.NET Compact Framework 中的图形和绘图