将触摸识别为MouseDown事件

Jor*_*ira 7 c# touch winforms

我正在用C#构建一个益智游戏,触摸屏的winforms.

我能够处理鼠标处理程序上的触摸事件,事实上,我什么也没做,但它已经识别出我的触摸.但是,有一个问题我无法弄清楚.mouse_down只发生在我移动我的手指时,并且在我触摸屏幕时无法识别.

有人已经遇到过这个问题吗?我应该实现一些触摸事件识别吗?如果是这样,你能指点一些文件或例子吗?

提前谢谢了

Jor*_*ira 9

谢谢@PiotrWolkowski

你对我应该遵循的方式是正确的...出现了一些其他问题,但我解决了覆盖WndProc的初始问题,如下所示:

protected override void WndProc(ref Message m)
    {
        switch (m.Msg)
        {
            case Win32.WM_POINTERDOWN:
            case Win32.WM_POINTERUP:
            case Win32.WM_POINTERUPDATE:
            case Win32.WM_POINTERCAPTURECHANGED:
                break;

            default:
                base.WndProc(ref m);
                return;
        }
        int pointerID = Win32.GET_POINTER_ID(m.WParam);
        Win32.POINTER_INFO pi = new Win32.POINTER_INFO();
        if (!Win32.GetPointerInfo(pointerID, ref pi))
        {
            Win32.CheckLastError();
        }
        Point pt = PointToClient(pi.PtPixelLocation.ToPoint());
        MouseEventArgs me = new MouseEventArgs(System.Windows.Forms.MouseButtons.Left, 1, pt.X, pt.Y, 0);
        switch (m.Msg)
        {
            case Win32.WM_POINTERDOWN:
                    Console.WriteLine("TOCOU" + pt);
                    (Parent as Jogo).Form1_MouseDown((this as object), me);
                break;

            case Win32.WM_POINTERUP:
                    Console.WriteLine("LEVANTOU");
                    (Parent as Jogo).Form1_MouseUp((this as object), me);
                break;

            case Win32.WM_POINTERUPDATE:
                    //Console.WriteLine("UPDATE");
                    (Parent as Jogo).Form1_MouseMove((this as object), me);
                break;
        }
    }
Run Code Online (Sandbox Code Playgroud)

它得到了"Win32.cs"的支持,可以在这里下载:

https://gist.github.com/RSchwoerer/bc5c04899c0510aefca24f088a79cebf

希望这对你有所帮助;)


Pio*_*ski 4

一个听起来似乎可行的解决方案的建议是重写 WndProc 并搜索 WM_TOUCH 事件。更多详细信息请参见:/sf/answers/1104973341/