捕获的DFP MonthCalendar控件在Windows窗体应用程序 [英] capture doubleclick for MonthCalendar control in windows forms app

查看:135
本文介绍了捕获的DFP MonthCalendar控件在Windows窗体应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何捕捉到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;
}

这篇关于捕获的DFP MonthCalendar控件在Windows窗体应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆