DateTimePicker.Value 属性

定义

获取或设置分配给控件的日期/时间值。

public:
 property DateTime Value { DateTime get(); void set(DateTime value); };
[System.ComponentModel.Bindable(true)]
public DateTime Value { get; set; }
[<System.ComponentModel.Bindable(true)>]
member this.Value : DateTime with get, set
Public Property Value As DateTime

属性值

DateTime

分配给控件的 DateTime 值。

属性

例外

返回值小于 MinDate 或大于 MaxDate

示例

下面的代码示例演示如何使用该 Value 属性检索当前日期值。 首先,该示例显示 Value 属性。 然后,该示例将属性递增 Value 一天,并再次显示属性值。

public:
   MyClass()
   {
      // Create a new DateTimePicker
      DateTimePicker^ dateTimePicker1 = gcnew DateTimePicker;
      array<Control^>^ myClassControls = {dateTimePicker1};
      Controls->AddRange( myClassControls );
      MessageBox::Show( dateTimePicker1->Value.ToString() );

      dateTimePicker1->Value = DateTime::Now.AddDays( 1 );
      MessageBox::Show( dateTimePicker1->Value.ToString() );
   }
public MyClass()
{
   // Create a new DateTimePicker
   DateTimePicker dateTimePicker1 = new DateTimePicker();
   Controls.AddRange(new Control[] {dateTimePicker1});
   MessageBox.Show(dateTimePicker1.Value.ToString());

   dateTimePicker1.Value = DateTime.Now.AddDays(1);
   MessageBox.Show(dateTimePicker1.Value.ToString());
}
Public Sub New()
   ' Create a new DateTimePicker
   Dim dateTimePicker1 As New DateTimePicker()
   Controls.AddRange(New Control() {dateTimePicker1})
   MessageBox.Show(dateTimePicker1.Value.ToString())
   
   dateTimePicker1.Value = DateTime.Now.AddDays(1)
   MessageBox.Show(dateTimePicker1.Value.ToString())
End Sub

注解

Value如果属性尚未在代码或用户中更改,则会将其设置为当前日期和时间 (DateTime.Now) 。

适用于

另请参阅