我已經成功地得到某種形式使用通過實施下面的代碼觸摸屏上時,我的FlowLayoutPanel的滾動的...vb.net FlowLayoutPanel的觸摸屏滾動
Dim mouseDownPoint As Point
Private Sub FlowLayoutPanelUsers_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs) Handles FlowLayoutPanelUsers.MouseDown
If (e.Button = MouseButtons.Left) Then
Me.mouseDownPoint = e.Location
End If
End Sub
Private Sub FlowLayoutPanelUsers_MouseMove(ByVal sender As Object, ByVal e As MouseEventArgs) Handles FlowLayoutPanelUsers.MouseMove
If (e.Button <> MouseButtons.Left) Then
Return
End If
If ((mouseDownPoint.X = e.Location.X) _
AndAlso (mouseDownPoint.Y = e.Location.Y)) Then
Return
End If
Dim currAutoS As Point = FlowLayoutPanelUsers.AutoScrollPosition
If (mouseDownPoint.Y > e.Location.Y) Then
'finger slide UP
If (currAutoS.Y <> 0) Then
currAutoS.Y = (Math.Abs(currAutoS.Y) - 1)
End If
ElseIf (mouseDownPoint.Y < e.Location.Y) Then
'finger slide down
currAutoS.Y = (Math.Abs(currAutoS.Y) + 1)
Else
currAutoS.Y = Math.Abs(currAutoS.Y)
End If
If (mouseDownPoint.X > e.Location.X) Then
'finger slide left
If (currAutoS.X <> 0) Then
currAutoS.X = (Math.Abs(currAutoS.X) - 1)
End If
ElseIf (mouseDownPoint.X < e.Location.X) Then
'finger slide right
currAutoS.X = (Math.Abs(currAutoS.X) + 1)
Else
currAutoS.X = Math.Abs(currAutoS.X)
End If
FlowLayoutPanelUsers.AutoScrollPosition = currAutoS
mouseDownPoint = e.Location
'IMPORTANT
End Sub
這是一些代碼,我已經找到在stackoverflow,所以感謝那初步!
如果可能,我希望此代碼執行的操作與其滾動的方式相反,因此如果向左滾動,FlowLayoutPanel會向右滾動,如果向上滾動,面板向下滾動,有點像Web瀏覽器。
有沒有人有任何見解呢?我已經嘗試了將負號反轉爲正號的簡單方法,反之亦然,但沒有效果。
在此先感謝。
好了,我發現e.Location.X爲代表的控制,而不是我想滾動父控件。在將e.Location更改爲... FlowLayoutPanelUsers.PointToClient(MousePosition)後,這可以起到一定的作用。以防萬一任何人想要做類似 –