Search code examples
winformswindows-7touchscreen

Buttons reaction on finger's touch in Windows 7


I have Windows 7 with touchscreen attached. My standard Windows Forms Application has several standard buttons.

My problem: buttons on form do not show reaction when I click on them using my finger. My form shows that there has been a click on the button but button itself does not react.

If I use cursor - everything works fine. If I use Windows XP - everything works fine.

Same thing with any standard application like calc.exe


Solution

  • I performed several experiments and now I believe problem with buttons reactions on touch is solved.

    1) Using WndProc I noticed that WM_LBUTTONDOWN and WM_LBUTTONUP messages were comming to my window at one and the same time (on finger release).

    2) I installed most recent driver, found setting Touch Mode and changed it to Mouse Emulation. This resolved the problem for my single touch screen. But problem remained the same for the multi touch screen.

    3) I created class:

    class TouchButton : Button
    {
        protected override void OnHandleCreated(EventArgs e)
        {
            base.OnHandleCreated(e);
            RegisterTouchWindow(Handle, 0);
        }
    
        protected override void OnHandleDestroyed(EventArgs e)
        {
            UnregisterTouchWindow(Handle);
            base.OnHandleDestroyed(e);
        }
    }
    

    4) I replaced all the generic Buttons with the TouchButtons and problem has gone!