Gets or sets the date/time value assigned to the control.
[Visual Basic]
Public Property Value As DateTime
[C#]
public DateTime Value {get; set;}
[C++]
public: __property DateTime get_Value();
public: __property void set_Value(DateTime);
[JScript]
public function get Value() : DateTime;
public function set Value(DateTime); Property Value
The DateTime value assign to the control.
Remarks
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).
Example
[Visual Basic, C#, C++] The following example demonstrates how use the Value property to retrieve the current date value. First, the example displays the Value property. The example then increments the Value property by one day and displays the property value again.
[Visual Basic]
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 'New
[C#]
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());
}
[C++]
public:
MyClass() {
// Create a new DateTimePicker
DateTimePicker* dateTimePicker1 = new DateTimePicker();
Control* myClassControls[] = {dateTimePicker1};
Controls->AddRange(myClassControls);
MessageBox::Show(dateTimePicker1->Value.ToString());
dateTimePicker1->Value = (System::DateTime::Now).AddDays(1);
MessageBox::Show(dateTimePicker1->Value.ToString());
}
[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button
in the upper-left corner of the page.
Requirements
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family
See Also
DateTimePicker Class | DateTimePicker Members | System.Windows.Forms Namespace | DateTime