简体   繁体   English

当用户单击DropDown按钮时,如何不在DateTimePicker中显示日历

[英]How not to show calendar in the DateTimePicker when user clicks DropDown button

In the DateTimePicker when user clicks DropDown button, a calendar gets displayed. DateTimePicker当用户单击DropDown按钮时,将显示日历。 I don't want to show calendar on the DropDown event. 我不想在DropDown事件上显示日历。

Is there some way to overwrite this event and to show custom form when user clicks DropDown button?? 是否有某种方法可以覆盖此事件并在用户单击DropDown按钮时显示自定义表单?

I don't want to show calendar on the DropDown event. 我不想在DropDown事件上显示日历。

You can prevent the calendar from being displayed by setting the control's ShowUpDown property to true . 您可以通过将控件的ShowUpDown属性设置true来阻止显示日历。 Instead of the drop-down calendar, it will instead show a spin button to the side of the DateTimePIcker control that allows the user to select the desired date/time. 它将代替下拉日历,而是在DateTimePIcker控件的一侧显示一个旋转按钮,允许用户选择所需的日期/时间。

Is there some way to overwrite this event and to show custom form when user clicks DropDown button?? 是否有某种方法可以覆盖此事件并在用户单击DropDown按钮时显示自定义表单?

Well, yeah, I guess so. 嗯,是的,我想是的。 You can handle the DropDown event , which gets raised when the control shows the drop-down calendar. 您可以处理DropDown事件 ,当控件显示下拉日历时会引发该事件 In this event handler, you could display whatever form you wanted. 在此事件处理程序中,您可以显示所需的任何表单。 The only problem is that the drop-down calendar is still going to be shown as normal. 唯一的问题是下拉日历仍然会正常显示。 I don't know how you prevent that from happening. 我不知道你是如何防止这种情况发生的。

You can, however, hack around it by forcing the drop-down calendar closed again. 但是,您可以通过强制再次关闭下拉日历来破解它。 To do that, P/Invoke the SendMessage function and send the control the DTM_CLOSEMONTHCAL message . 为此,P / Invoke SendMessage函数并向控件发送DTM_CLOSEMONTHCAL消息

[DllImport("user32.dll", CharSet = CharSet.Auto)]
private static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);

private const uint DTM_FIRST         = 0x1000;
private const uint DTM_CLOSEMONTHCAL = DTM_FIRST + 13; 

public static void CloseCalendar(this DateTimePicker dtp)
{
    SendMessage(dtp.Handle, DTM_CLOSEMONTHCAL, IntPtr.Zero, IntPtr.Zero);
}

But I can't imagine the reason you would want to do this. 但我无法想象你想要这样做的原因。 If you don't want a calendar or a spin-button control, then you don't want a DateTimePicker. 如果您不想要日历或旋转按钮控件,那么您不需要DateTimePicker。 Just use a regular combo box or a drop-down button, then you can display whatever form you want when it is clicked. 只需使用常规组合框或下拉按钮,即可在单击时显示所需的任何表单。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 用户单击列表框项时如何显示按钮? - How to show button when the user clicks a listbox item? 显示带有派生的DateTimePicker类的自定义日历下拉列表 - Show a custom calendar dropdown with a derived DateTimePicker class 当用户单击文本输入框时如何在@Html.EditorFor() 中显示下拉列表 - How to show dropdown list in the @Html.EditorFor() when user clicks on the text input box 如何以编程方式关闭 datetimepicker 的下拉日历或更新下拉日历以反映 .Value 属性? - How can I programmatically close the dropdown calendar of a datetimepicker or update the dropdown calendar to reflect the .Value property? 用户单击MessageDialog上的按钮时如何调用FileSavePicker? - How to call FileSavePicker when user clicks button on MessageDialog? DateTimePicker:如果用户在弹出式日历中单击/选择日期,该如何处理? - DateTimePicker: How will I handle if the user clicked/selected date in the popup calendar or not? 如何将 datetimepicker 下拉菜单设置为仅显示月份 - How can I set the datetimepicker dropdown to show Months only 用户单击按钮时重定向到登录页面 - Redirecting to login page when user clicks a button 用户单击单选按钮时触发事件 - Firing an event when a user clicks a radio button 当用户单击asp按钮时,如何模拟键盘按钮的按下? - How do I simulate keyboard button press when the user clicks on asp button?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM