Windows 窗体触摸事件 [英] Windows Forms touch down event

查看:31
本文介绍了Windows 窗体触摸事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个 Windows 窗体应用程序,该应用程序有几个可点击的面板,这些面板需要与鼠标按下和按下事件等效的触摸屏.

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.

当我使用键盘和鼠标进行测试时,事件会正确触发,应用程序会按预期做出反应.但是,在触摸屏上进行测试时并非如此.唯一能正常工作的事件是点击事件,但我的应用程序需要鼠标按下事件来持续更新值.

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?

推荐答案

您必须覆盖 WndProc,捕获消息并手动启动 MouseDown 和 MouseUp 事件

You have to override the WndProc, capture the messages and launch your MouseDown and MouseUp events manually

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;
            }
    }
}

这篇关于Windows 窗体触摸事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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