DateTimePicker.MaxDateTime 字段
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
指定 DateTimePicker 控件的最大日期值。 此字段为只读。
public: static initonly DateTime MaxDateTime;
public static readonly DateTime MaxDateTime;
[System.ComponentModel.Browsable(false)]
public static readonly DateTime MaxDateTime;
staticval mutable MaxDateTime : DateTime
[<System.ComponentModel.Browsable(false)>]
staticval mutable MaxDateTime : DateTime
Public Shared ReadOnly MaxDateTime As DateTime
字段值
- 属性
示例
下面的代码示例演示如何处理 DropDownDateTimePicker 事件并使用 MinDateTime 和 MaxDateTime 字段。 若要运行此示例,请将以下代码粘贴到包含名为 DateTimePicker1
的DateTimePicker窗体中。
// When the calendar drops down, display a MessageBox indicating
// that DateTimePicker will not accept dates before MinDateTime or
// after MaxDateTime. Use a StringBuilder object to build the string
// for efficiency.
void DateTimePicker1_DropDown( Object^ /*sender*/, System::EventArgs^ /*e*/ )
{
System::Text::StringBuilder^ messageBuilder = gcnew System::Text::StringBuilder;
messageBuilder->Append( "Choose a date after: " );
messageBuilder->Append( DateTimePicker::MinDateTime.ToShortDateString() );
messageBuilder->Append( " and a date before: " );
messageBuilder->Append( DateTimePicker::MaxDateTime.ToShortDateString() );
MessageBox::Show( messageBuilder->ToString() );
}
// When the calendar drops down, display a MessageBox indicating
// that DateTimePicker will not accept dates before MinDateTime or
// after MaxDateTime. Use a StringBuilder object to build the string
// for efficiency.
private void DateTimePicker1_DropDown(object sender,
System.EventArgs e)
{
System.Text.StringBuilder messageBuilder =
new System.Text.StringBuilder();
messageBuilder.Append("Choose a date after: ");
messageBuilder.Append
(DateTimePicker.MinDateTime.ToShortDateString());
messageBuilder.Append(" and a date before: ");
messageBuilder.Append
(DateTimePicker.MaxDateTime.ToShortDateString());
MessageBox.Show(messageBuilder.ToString());
}
' When the calendar drops down, display a MessageBox indicating
' that DateTimePicker will not accept dates before MinDateTime or
' after MaxDateTime. Use a StringBuilder object to build the string
' for efficiency.
Private Sub DateTimePicker1_DropDown(ByVal sender As Object, _
ByVal e As EventArgs) Handles DateTimePicker1.DropDown
Dim messageBuilder As New System.Text.StringBuilder
messageBuilder.Append("Choose a date after: ")
messageBuilder.Append(DateTimePicker.MinDateTime.ToShortDateString)
messageBuilder.Append(" and a date before: ")
messageBuilder.Append(DateTimePicker.MaxDateTime.ToShortDateString)
MessageBox.Show(messageBuilder.ToString())
End Sub
注解
最大日期设置为 9998 年 12 月 31 日 23:59:59。