捕获的DFP MonthCalendar控件在Windows窗体应用程序窗体、控件、应用程序、DFP

由网友(我把心寄错了地址)分享简介:我如何捕捉到MonthCalendar控件的双击事件?我使用的MouseDown的MouseEventArgs.Clicks性尝试,但它始终是1,即使我双击。How do I capture a doubleclick event of the MonthCalendar control? I've tried us...

我如何捕捉到MonthCalendar控件的双击事件?我使用的MouseDown的MouseEventArgs.Clicks性尝试,但它始终是1,即使我双击。

How do I capture a doubleclick event of the MonthCalendar control? I've tried using MouseDown's MouseEventArgs.Clicks property, but it is always 1, even if I doubleclick.

推荐答案

请注意,既不MonthCalendar控件显示的DoubleClick,也不是MouseDoubleClick事件在属性窗口中。麻烦肯定的标志,本机Windows控制prevents从如何产生这些事件。您可以通过观看在MouseDown事件并测量点击之间的时间合成你自己的。

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.

添加一个新类到您的项目并粘贴下面所示的code。编译。从工具箱顶部的新的控制。写一个事件处理程序DoubleClickEx事件。

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.

using System;
using System.Windows.Forms;

class MyCalendar : MonthCalendar {
    public event EventHandler DoubleClickEx;

    public MyCalender() {
        lastClickTick = Environment.TickCount - SystemInformation.DoubleClickTime;
    }

    protected override void OnMouseDown(MouseEventArgs e) {
        int tick = Environment.TickCount;
        if (tick - lastClickTick <= SystemInformation.DoubleClickTime) {
            EventHandler handler = DoubleClickEx;
            if (handler != null) handler(this, EventArgs.Empty);
        }
        else {
            base.OnMouseDown(e);
            lastClickTick = tick;
        }
    }

    private int lastClickTick;
}
阅读全文

相关推荐

最新文章