通过实施以下代码,我在使用触摸屏时设法在我的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向右滚动,如果我向上滚动,Panel向下滚动,有点像Web浏览器。
有没有人对此有任何见解?我已经尝试了将减号反转为加号的简单方法,反之亦然,但没有效果。
提前致谢。
答案 0 :(得分:0)
修改代码......
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 = FlowLayoutPanelUsers.PointToClient(MousePosition)
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 = FlowLayoutPanelUsers.PointToClient(MousePosition).X) _
AndAlso (mouseDownPoint.Y = FlowLayoutPanelUsers.PointToClient(MousePosition).Y)) Then
Return
End If
Dim currAutoS As Point = FlowLayoutPanelUsers.AutoScrollPosition
If (mouseDownPoint.Y > FlowLayoutPanelUsers.PointToClient(MousePosition).Y) Then
'finger slide UP
If (currAutoS.Y <> 0) Then
currAutoS.Y = (Math.Abs(currAutoS.Y) - 1)
End If
ElseIf (mouseDownPoint.Y < FlowLayoutPanelUsers.PointToClient(MousePosition).Y) Then
'finger slide down
currAutoS.Y = (Math.Abs(currAutoS.Y) + 1)
Else
currAutoS.Y = Math.Abs(currAutoS.Y)
End If
If (mouseDownPoint.X > FlowLayoutPanelUsers.PointToClient(MousePosition).X) Then
'finger slide left
If (currAutoS.X <> 0) Then
currAutoS.X = (Math.Abs(currAutoS.X) - 1)
End If
ElseIf (mouseDownPoint.X < FlowLayoutPanelUsers.PointToClient(MousePosition).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 = FlowLayoutPanelUsers.PointToClient(MousePosition)
'IMPORTANT
End Sub