Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows Forms touch down event

Tags:

c#

winforms

touch

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?

like image 676
Sand0rf Avatar asked Apr 03 '13 10:04

Sand0rf


2 Answers

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.

like image 139
James Barrass Avatar answered Oct 01 '22 03:10

James Barrass


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;
            }
    }
}
like image 30
Francesco Avatar answered Oct 01 '22 05:10

Francesco