您的位置:首页 > 其它

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

2009-02-23 12:56 525 查看
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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐