We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to prevent the Calendar popup from hiding upon mouse selection of the "Today" or "None" button?

Platform: WinForms |
Control: DateTimePickerAdv |
Published Date: November 21, 2014 |
Last Revised Date: May 23, 2019

In the DateTimerPickerAdv, the MonthCalender, popup is hidden upon mouse button selection of the None and Today buttons. The popup visibility can be maintained by the following steps:

  1. Handling the BeforeCloseUp event.
  2. Using the DisplayCalendar function.

 

By using the BeforeCloseUp event handler

In the DataTimePickerAdv, the CalenderPopup is hidden on clicking Today and None buttons. It is possible to maintain the CalenderPopup visibility in this case by handling the BeforeCloseUp event and None and Today buttons’ MouseDown event.

The following code example demonstrates the same.

C#

//Initializes the variable.
private bool preventFromPopup = false;
// Raises the events.
this.dateTimePickerAdv1.PopupWindow.BeforeCloseUp += new CancelEventHandler(PopupWindow_BeforeCloseUp);
this.dateTimePickerAdv1.PopupWindow.Calendar.NoneButton.MouseDown += new MouseEventHandler(NoneButton_MouseDown);
this.dateTimePickerAdv1.PopupWindow.Calendar.TodayButton.MouseDown += new MouseEventHandler(TodayButton_MouseDown);
// Raises the event when the Mouse is pressed on the None Button.
void NoneButton_MouseDown(object sender, MouseEventArgs e)
{
    preventFromPopup = true;
}
// Raises the event when the Mouse pressed on the Today Button.
void TodayButton_MouseDown(object sender, MouseEventArgs e)
{
    preventFromPopup = true;
}
// Prevents the popup window from hiding.
void PopupWindow_BeforeCloseUp(object sender, CancelEventArgs e)
{
    if (preventFromPopup)
        e.Cancel = true;
}

 

VB

'Initializes the variable.
Private preventFromPopup As Boolean = False
'Raises the events.
AddHandler dateTimePickerAdv1.PopupWindow.BeforeCloseUp, AddressOf PopupWindow_BeforeCloseUp
AddHandler dateTimePickerAdv1.PopupWindow.Calendar.NoneButton.MouseDown, AddressOf NoneButton_MouseDown
AddHandler dateTimePickerAdv1.PopupWindow.Calendar.TodayButton.MouseDown, AddressOf TodayButton_MouseDown
'Raises the event when the Mouse pressed on the None Button.
Private Sub NoneButton_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs)
 preventFromPopup = True
End Sub
'Raises the event when the Mouse pressed on the Today Button.
Private Sub TodayButton_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs)
 preventFromPopup = True
End Sub
'Prevents the popup window from hiding.
Private Sub PopupWindow_BeforeCloseUp(ByVal sender As Object, ByVal e As CancelEventArgs)
 If preventFromPopup Then
  e.Cancel = True
 End If
End Sub

 

By using the DisplayCalendar method

The purpose of the DisplayCalendar function is to display the MonthCalendar popup programmatically. So, the Popup can be displayed by invoking the DisplayCalendar function in its None and Today button click events.

The following code example demonstrates the same.

C#

// Raises the event.
this.dateTimePickerAdv1.PopupWindow.Calendar.TodayButton.Click += new EventHandler(TodayButton_Click);
this.dateTimePickerAdv1.PopupWindow.Calendar.NoneButtonClick += new EventHandler(Calendar_NoneButtonClick);
//Shows the calendar by using the DisplayMethod.
void Calendar_NoneButtonClick(object sender, EventArgs e)
{
    this.dateTimePickerAdv1.DisplayCalendar();
}
void TodayButton_Click(object sender, EventArgs e)
{
    this.dateTimePickerAdv1.DisplayCalendar();
}

 

VB

'Raises the events.
AddHandler dateTimePickerAdv1.PopupWindow.Calendar.TodayButton.Click, AddressOf TodayButton_Click
AddHandler dateTimePickerAdv1.PopupWindow.Calendar.NoneButtonClick, AddressOf Calendar_NoneButtonClick
'Shows the calendar by using the DisplayMethod.
Private Sub Calendar_NoneButtonClick(ByVal sender As Object, ByVal e As EventArgs)
 Me.dateTimePickerAdv1.DisplayCalendar()
End Sub
Private Sub TodayButton_Click(ByVal sender As Object, ByVal e As EventArgs)
 Me.dateTimePickerAdv1.DisplayCalendar()
End Sub

 

Showing popup window

Figure 1: The popup window does not hide, when clicking on the Today or None button

Sample Links:

C#: DateTimePickerAdv_CalendarPopup_C#

VB: DateTimePickerAdv_CalendarPopup_VB

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon