简体   繁体   English

Windows 窗体触摸事件

[英]Windows Forms touch down event

I'm creating a Windows Forms application that has a couple of clickable panels that require the touchscreen equivalent of the mouse down and up event.我正在创建一个 Windows 窗体应用程序,它有几个可点击的面板,这些面板需要与鼠标按下和松开事件等效的触摸屏。

When I'm testing with my keyboard and mouse the event are fired correctly and the application reacts as expected.当我用我的键盘和鼠标进行测试时,事件被正确触发,应用程序按预期做出反应。 However when testing on a touchscreen it is not.但是,在触摸屏上进行测试时并非如此。 The only event that does work correctly is the click event but my application requires a mouse down event to continuously update a value.唯一能正常工作的事件是单击事件,但我的应用程序需要鼠标按下事件来持续更新值。

Has anyone encountered a problem like this and found a solution?有没有人遇到过这样的问题并找到了解决方案?

Just doing a little reading, I think you need to override the WndProc and look for WM_TOUCH events.只是做一点阅读,我认为您需要覆盖 WndProc 并查找 WM_TOUCH 事件。

Have a look at the Windows 7 Multitouch .NET Interop Sample Library which has examples on handling touch and gestures in winforms.查看Windows 7 Multitouch .NET Interop Sample Library ,其中包含有关在 winforms 中处理触摸和手势的示例。

You have to override the WndProc, capture the messages and launch your MouseDown and MouseUp events manually您必须覆盖 WndProc,捕获消息并手动启动 MouseDown 和 MouseUp 事件

public const int WM_POINTERDOWN = 0x246;
public const int WM_POINTERUP = 0x247;

[PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
protected override void WndProc(ref Message m)
{
    base.WndProc(m);
    switch (m.Msg)
    {
        case WM_POINTERDOWN:
            {
                MouseEventArgs args = new MouseEventArgs(MouseButtons.Left, 1, this.MousePosition.X, this.MousePosition.Y, 0);
                MouseDown(this, args);                    
                break;
            }

        case WM_POINTERUP:
            {
                MouseEventArgs args = new MouseEventArgs(MouseButtons.Left, 1, this.MousePosition.X, this.MousePosition.Y, 0);
                MouseUp(this, args);
                break;
            }
    }
}

我对此并不完全确定,但是,您是否尝试过使用点击事件而不是点击事件来捕获触摸?

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM