Export (0) Print
Expand All

DateTimePicker.MaxDate Property

Gets or sets the maximum date and time that can be selected in the control.

[Visual Basic]
Public Property MaxDate As DateTime
[C#]
public DateTime MaxDate {get; set;}
[C++]
public: __property DateTime get_MaxDate();
public: __property void set_MaxDate(DateTime);
[JScript]
public function get MaxDate() : DateTime;
public function set MaxDate(DateTime);

Property Value

The maximum date and time that can be selected in the control. The default is 12/31/9998 23:59:59.

Exceptions

Exception Type Condition
ArgumentException The value assigned is less than MinDate value.
SystemException The value assigned is greater than the MaxDateTime value.

Example

[Visual Basic, C#, C++] The following example creates an new instance of a DateTimePicker control and initializes it. The control's CustomFormat property is set. Also, the ShowCheckBox property is set so that the control displays a CheckBox, and the ShowUpDown property is set so that the control is displayed as an up-down control.

[Visual Basic] 
Public Sub CreateMyDateTimePicker()
    ' Create a new DateTimePicker control and initialize it.
    Dim dateTimePicker1 As New DateTimePicker()
    
    ' Set the MinDate and MaxDate.
    dateTimePicker1.MinDate = New DateTime(1985, 6, 20)
    dateTimePicker1.MaxDate = DateTime.Today
    
    ' Set the CustomFormat string.
    dateTimePicker1.CustomFormat = "MMMM dd, yyyy - dddd"
    dateTimePicker1.Format = DateTimePickerFormat.Custom
    
    ' Show the CheckBox and display the control as an up-down control.
    dateTimePicker1.ShowCheckBox = True
    dateTimePicker1.ShowUpDown = True
End Sub 'CreateMyDateTimePicker

[C#] 
public void CreateMyDateTimePicker()
{
   // Create a new DateTimePicker control and initialize it.
   DateTimePicker dateTimePicker1 = new DateTimePicker();

   // Set the MinDate and MaxDate.
   dateTimePicker1.MinDate = new DateTime(1985, 6, 20);
   dateTimePicker1.MaxDate = DateTime.Today;

   // Set the CustomFormat string.
   dateTimePicker1.CustomFormat = "MMMM dd, yyyy - dddd";
   dateTimePicker1.Format = DateTimePickerFormat.Custom;

   // Show the CheckBox and display the control as an up-down control.
   dateTimePicker1.ShowCheckBox = true;
   dateTimePicker1.ShowUpDown = true;
}
   

[C++] 
public:
void CreateMyDateTimePicker()
{
   // Create a new DateTimePicker control and initialize it.
   DateTimePicker* dateTimePicker1 = new DateTimePicker();

   // Set the MinDate and MaxDate.
   dateTimePicker1->MinDate = DateTime(1985, 6, 20);
   dateTimePicker1->MaxDate = DateTime::Today;

   // Set the CustomFormat string.
   dateTimePicker1->CustomFormat = S"MMMM dd, yyyy - dddd";
   dateTimePicker1->Format = DateTimePickerFormat::Custom;

   // Show the CheckBox and display the control as an up-down control.
   dateTimePicker1->ShowCheckBox = true;
   dateTimePicker1->ShowUpDown = true;
}
   

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter 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 | MaxDateTime | MinDate

Show:
© 2014 Microsoft