Windows Forms touch down event

后端 未结 3 630
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-19 02:52

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 te

相关标签:
3条回答
  • 2021-01-19 03:22

    Just doing a little reading, I think you need to override the WndProc and look for WM_TOUCH events.

    Have a look at the Windows 7 Multitouch .NET Interop Sample Library which has examples on handling touch and gestures in winforms.

    0 讨论(0)
  • 2021-01-19 03:32

    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;
                }
        }
    }
    
    0 讨论(0)
  • 2021-01-19 03:37

    I'm not completely sure about this but, have you tried using a tap event to capture the touch, rather than the click event?

    0 讨论(0)
提交回复
热议问题