Share via

Visual Studio C# Windows Forms Application touch screen exception error

Anonymous
2024-06-06T04:09:05+00:00

I have Windows Forms Visual Studio Project; I have added the code to be able to use a finger instead of the mouse on touch screen monitor.

When I use a mouse, everything is working, but when I use a finger to top and double top on the screen also working only if I do it on any item on the form, but wh

en I use a finger on a form (on the empty space) I get an exception error, I attached a picture as well as code for the finger as a pointer.

Anyone knows what should be done, thanks in advance.

Code Here:

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 Form1).Form1_MouseDown((this as object), me);

            break;

        case Win32.WM_POINTERUP:

            Console.WriteLine("LEVANTOU");

            (Parent as Form1).Form1_MouseUp((this as object), me);

            break;

        case Win32.WM_POINTERUPDATE:

            Console.WriteLine("UPDATE");

            (Parent as Form1).Form1_MouseMove((this as object), me);

            break;

    }

}

Windows for home | Windows 11 | Devices and drivers

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Gopal Krish 2,865 Reputation points Independent Advisor
2024-06-06T05:41:50+00:00

Hello there, I'm Gopal an Independent Advisor. I will try my best to help you.

I apologize for the inconvenience. As the Community forum is primarily focused on consumer-related questions, I kindly request that you post your question on our sister forum, Microsoft Q&A. This platform is specifically designed for IT administrators, developers, and professionals, providing a better chance of receiving a knowledgeable and prompt response to your query. You can submit your question by visiting the following link: https://learn.microsoft.com/en-us/answers/tags/...

Regards,

Gopal

Was this answer helpful?

1 person found this answer helpful.
0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Anonymous
    2024-06-06T06:16:56+00:00

    Sorry about that, will do.

    Was this answer helpful?

    0 comments No comments