1
votes

In my c# windows forms code I'd like to detect once a button is pressed (and perform an action) and when a button is released (and perform another action).

I know the existance of MouseDown and MouseUp events and up to Windows XP everything was fine.

The problem comes now with Windows 7 and a capacitive touchscreen, when Microsoft introduces gesture and "PressAndHold" function: the MouseDown events is recevide several seconds after the user touches the screen. (N.B. using a mouse everything works fine).

How can I avoid this annoing delay before receiving the MouseDown event?

I already tried with GlobalAddAtom("MicrosoftTabletPenServiceProperty") and I had a little change: I do not receive the RightButton anymore, I receive LeftButton instead, but always after the same amount of time.

I also tried with MouseHover event with if (MouseButtons == MouseButtons.Left) but without success (it works with mouse only, not touch).

N.B. I need to let gesture and pressandhold feature active for other controls in the form.

2

2 Answers

2
votes

I think I found a way on my Windows 7 touch:

I have to disable PressAndHold and also register the button as touch, so I get the MouseDown event almost immediately for that button, preserving gesture for all other controls.

TogglePressAndHold(btnMoveUp.Handle, false);

RegisterTouchWindow(btnMoveUp.Handle, 0);

For first function refer to this MSDN article: https://msdn.microsoft.com/en-us/library/ms812373.aspx

RegisterTouchWindow is a User32.dll function

Hope to be of some help for others. Let me know if it works also on others platforms.

0
votes

Have you tried using the Control.Click Event ?