在 Windows 窗体应用程序中捕获 MonthCalendar 控件的双击
如何捕获 System.Windows.Forms.MonthCalendar 控件的双击事件?我尝试过使用 MouseDown 的 MouseEventArgs.Clicks 属性,但它始终为 1,即使我双击也是如此。
How do I capture a doubleclick event of the System.Windows.Forms.MonthCalendar control? I've tried using MouseDown's MouseEventArgs.Clicks property, but it is always 1, even if I doubleclick.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
请注意,MonthCalendar 在“属性”窗口中既不显示 DoubleClick 也不显示 MouseDoubleClick 事件。麻烦的明显迹象是,本机 Windows 控件会阻止生成这些事件。您可以通过观察 MouseDown 事件并测量单击之间的时间来合成您自己的。
将新类添加到您的项目中并粘贴下面所示的代码。编译。从工具箱顶部放下新控件。为 DoubleClickEx 事件编写一个事件处理程序。
Do note that MonthCalendar neither shows the DoubleClick nor the MouseDoubleClick event in the Property window. Sure sign of trouble, the native Windows control prevents those events from getting generated. You can synthesize your own by watching the MouseDown events and measuring the time between clicks.
Add a new class to your project and paste the code shown below. Compile. Drop the new control from the top of the toolbox. Write an event handler for the DoubleClickEx event.
您需要自己跟踪点击事件。您需要使用 DateSelected 事件来标记单击日期的时间,并使用 DateChanged 事件来“重置”时间跨度,这样您就不会将单击不同的日期算作双击。
注意:如果您使用鼠标按下事件,则会出现错误行为
无论单击什么,鼠标按下事件都会发生,例如单击日历的月/年等标题将仅注册与点击真实日期相同。因此使用 DateSelected 而不是鼠标按下事件。
You'll need to keep track of the click events yourself. You need to use the DateSelected event to mark when a date is clicked, and the DateChanged event to 'reset' the time span so you don't count clicking different dates as a double click.
Note: if you use a mouse down event you will get buggy behavior
The mouse down event occurs no matter what is clicked, for example clicking on the month / year etc header of the Calendar will be registered just the same as clicking a real date. Hence the use of DateSelected instead of the mouse down event.
最好添加以下代码,否则如果您快速单击两个日期,您将获得该事件。
Best to add following code, otherwise if you click quickly on two dates you will have the event.