DateTimePicker.Value 属性

定义

获取或设置分配给控件的日期/时间值。Gets or sets the date/time value assigned to the control.

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

属性值

分配给控件的 DateTime 值。The DateTime value assign to the control.

属性

例外

返回值小于 MinDate 或大于 MaxDateThe set value is less than MinDate or more than MaxDate.

示例

下面的代码示例演示如何使用 Value 属性检索当前日期值。The following code example demonstrates how use the Value property to retrieve the current date value. 首先,该示例显示 "Value" 属性。First, the example displays the Value property. 然后,该示例将 Value 属性递增一天,并再次显示该属性值。The example then increments the Value property by one day and displays the property value again.

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)。If the Value property has not been changed in code or by the user, it is set to the current date and time (DateTime.Now).

适用于

另请参阅