在winforms应用程序中检测各种触摸事件

我有一个带5个触摸点的触摸屏显示器。 我想在一个新的Windows窗体应用程序中做一些触摸工作,但我很难找到资源。

是否可以在winforms应用程序中处理触摸事件? 我不只是在谈论攻丝。 我的意思是像Pinching,Swiping(两个手指滑动),抓取和扭曲/旋转和缩放?

我们怎样才能发现捏?

看看WM_GESTURE消息 ,我想你可以在这里得到一些信息, 这也可能是好的 ,可能就是这样

由于我不能评论你的post,不要把它作为一个完整的答案。 我尽我所能!

Microsoft提供了一组C#interop库,可以让您检测WinForms中的触摸和手势。 它被称为“Windows 7 Multitouch .NET Interop示例库”。 旧链接在这里 ,但似乎已经死了。 目前,它位于Google Code上 。 存档的原始名称是Win7RC_MT.zip。 我在WinForms应用程序中使用它非常成功。

为winforms添加手势支持 – 在此解决:

LIEW HON CHIN的论文:

http://portal.fke.utm.my/libraryfke/files/1387_LIEWHONCHIN2011.pdf

'Imports System.Security.Permissions 'Imports System.Runtime.InteropServices Private first_point As New Point() Private second_point As New Point() Private iArguments As Integer = 0 Private Const ULL_ARGUMENTS_BIT_MASK As Int64 = &HFFFFFFFFL Private Const WM_GESTURENOTIFY As Integer = &H11A Private Const WM_GESTURE As Integer = &H119 Private Const GC_ALLGESTURES As Integer = &H1 Private Const GID_BEGIN As Integer = 1 Private Const GID_END As Integer = 2 Private Const GID_ZOOM As Integer = 3 Private Const GID_PAN As Integer = 4 Private Const GID_ROTATE As Integer = 5 Private Const GID_TWOFINGERTAP As Integer = 6 Private Const GID_PRESSANDTAP As Integer = 7 Private Const GF_BEGIN As Integer = &H1 Private Const GF_INERTIA As Integer = &H2 Private Const GF_END As Integer = &H4 Private Structure GESTURECONFIG Public dwID As Integer Public dwWant As Integer Public dwBlock As Integer End Structure Private Structure POINTS Public x As Short Public y As Short End Structure Private Structure GESTUREINFO Public cbSize As Integer Public dwFlags As Integer Public dwID As Integer Public hwndTarget As IntPtr  Friend ptsLocation As POINTS Public dwInstanceID As Integer Public dwSequenceID As Integer Public ullArguments As Int64 Public cbExtraArgs As Integer End Structure  _ Private Shared Function SetGestureConfig(ByVal hWnd As IntPtr, ByVal dwReserved As Integer, ByVal cIDs As Integer, ByRef pGestureConfig As GESTURECONFIG, ByVal cbSize As Integer) As  Boolean End Function  Private Shared Function GetGestureInfo(ByVal hGestureInfo As IntPtr, ByRef pGestureInfo As GESTUREINFO) As  Boolean End Function Private _gestureConfigSize As Integer Private _gestureInfoSize As Integer  Private Sub SetupStructSizes() _gestureConfigSize = Marshal.SizeOf(New GESTURECONFIG()) _gestureInfoSize = Marshal.SizeOf(New GESTUREINFO()) End Sub  Protected Overrides Sub WndProc(ByRef m As Message) Dim handled As Boolean Select Case m.Msg Case WM_GESTURENOTIFY Dim gc As New GESTURECONFIG() gc.dwID = 0 gc.dwWant = GC_ALLGESTURES gc.dwBlock = 0 Dim bResult As Boolean = SetGestureConfig(Handle, 0, 1, gc, _gestureConfigSize) If Not bResult Then Throw New Exception("Error in execution of SetGestureConfig") End If handled = True Case WM_GESTURE handled = DecodeGesture(m) Case Else handled = False End Select MyBase.WndProc(m) If handled Then Try m.Result = New IntPtr(1) Catch excep As Exception Debug.Print("Could not allocate result ptr") Debug.Print(excep.ToString()) End Try End If End Sub Private Function DecodeGesture(ByRef m As Message) As Boolean Dim gi As GESTUREINFO Try gi = New GESTUREINFO() Catch excep As Exception Debug.Print("Could not allocate resources to decode gesture") Debug.Print(excep.ToString()) Return False End Try gi.cbSize = _gestureInfoSize If Not GetGestureInfo(m.LParam, gi) Then Return False End If Select Case gi.dwID Case GID_BEGIN, GID_END Case GID_TWOFINGERTAP 'Receipt.Show() 'Invalidate() Case GID_ZOOM Select Case gi.dwFlags Case GF_BEGIN iArguments = CInt(Fix(gi.ullArguments And ULL_ARGUMENTS_BIT_MASK)) first_point.X = gi.ptsLocation.x first_point.Y = gi.ptsLocation.y first_point = PointToClient(first_point) Case Else second_point.X = gi.ptsLocation.x second_point.Y = gi.ptsLocation.y second_point = PointToClient(second_point) RaiseEvent GestureHappened(Me, New GestureEventArgs With {.Operation = Gestures.Pan, .FirstPoint = first_point, .SecondPoint = second_point}) 'Invalidate() 'MsgBox("zoom") End Select Case GID_PAN Select Case gi.dwFlags Case GF_BEGIN first_point.X = gi.ptsLocation.x first_point.Y = gi.ptsLocation.y first_point = PointToClient(first_point) Case Else second_point.X = gi.ptsLocation.x second_point.Y = gi.ptsLocation.y second_point = PointToClient(second_point) RaiseEvent GestureHappened(Me, New GestureEventArgs With {.Operation = Gestures.Pan, .FirstPoint = first_point, .SecondPoint = second_point}) 'Invalidate() 'MsgBox("pan") End Select Case GID_PRESSANDTAP 'If gi.dwFlags = GF_BEGIN Then ' Invalidate() 'End If Case GID_ROTATE 'Select Case gi.dwFlags ' Case GF_BEGIN ' iArguments = 0 ' Case Else ' first_point.X = gi.ptsLocation.x ' first_point.Y = gi.ptsLocation.y ' first_point = PointToClient(first_point) ' Invalidate() 'End Select End Select Return True End Function Public Enum Gestures Pan Zoom End Enum Public Class GestureEventArgs Inherits EventArgs Public Property Operation As Gestures Public Property FirstPoint As Point Public Property SecondPoint As Point End Class Public Event GestureHappened(sender As Object, e As GestureEventArgs)