DateTimePicker.DropDown 事件
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
当显示下拉日历时发生。
public:
event EventHandler ^ DropDown;
public event EventHandler DropDown;
public event EventHandler? DropDown;
member this.DropDown : EventHandler
Public Custom Event DropDown As EventHandler
事件类型
示例
下面的代码示例演示如何使用 MinDateTime 和 MaxDateTime 字段处理 DropDown 的 DateTimePicker 事件。 若要运行此示例,请将以下代码粘贴到包含 DateTimePicker 名为 DateTimePicker1
的窗体中。
// 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
注解
有关处理事件的详细信息,请参阅 处理和引发事件。