DateTimePicker.Value Property
.NET Framework 4
Gets or sets the date/time value assigned to the control.
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
| Exception | Condition |
|---|---|
| ArgumentOutOfRangeException |
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).
The following code 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.
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()); }
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.