DateTimePicker.MaxDate 属性

获取或设置可在控件中选择的最大日期和时间。

**命名空间:**System.Windows.Forms
**程序集:**System.Windows.Forms(在 system.windows.forms.dll 中)

语法

声明
Public Property MaxDate As DateTime
用法
Dim instance As DateTimePicker
Dim value As DateTime

value = instance.MaxDate

instance.MaxDate = value
public DateTime MaxDate { get; set; }
public:
property DateTime MaxDate {
    DateTime get ();
    void set (DateTime value);
}
/** @property */
public DateTime get_MaxDate ()

/** @property */
public void set_MaxDate (DateTime value)
public function get MaxDate () : DateTime

public function set MaxDate (value : DateTime)

属性值

可在控件中选择的最大日期和时间。默认值为 12/31/9998 23:59:59。

异常

异常类型 条件

ArgumentException

分配的值小于 MinDate 值。

SystemException

分配的值大于 MaxDateTime 值。

示例

下面的代码示例创建 DateTimePicker 控件的一个新实例并将其初始化。设置控件的 CustomFormat 属性。此外,还要设置 ShowCheckBox 属性以便此控件显示 CheckBox;并设置 ShowUpDown 属性以便此控件显示为数值调节钮控件(也称为 up-down 控件)。

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
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;
}
   
public:
   void CreateMyDateTimePicker()
   {
      // Create a new DateTimePicker control and initialize it.
      DateTimePicker^ dateTimePicker1 = gcnew DateTimePicker;
      
      // Set the MinDate and MaxDate.
      dateTimePicker1->MinDate = 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;
   }
public void CreateMyDateTimePicker()
{
    // Create a new DateTimePicker control and initialize it.
    DateTimePicker dateTimePicker1 = new DateTimePicker();

    // Set the MinDate and MaxDate.
    dateTimePicker1.set_MinDate(new DateTime(1985, 6, 20));
    dateTimePicker1.set_MaxDate(DateTime.get_Today());

    // Set the CustomFormat string.
    dateTimePicker1.set_CustomFormat("MMMM dd, yyyy - dddd");
    dateTimePicker1.set_Format(DateTimePickerFormat.Custom);

    // Show the CheckBox and display the control as an up-down control.
    dateTimePicker1.set_ShowCheckBox(true);
    dateTimePicker1.set_ShowUpDown(true);
} //CreateMyDateTimePicker

平台

Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

.NET Compact Framework

受以下版本支持:2.0

请参见

参考

DateTimePicker 类
DateTimePicker 成员
System.Windows.Forms 命名空间
MaxDateTime
MinDate