vb.net 中窗体上添加一个VScrollBar,怎么样才能使,鼠标中轴滚动,VScrollBar也跟着滚动

谢谢
2024-12-27 20:31:12
推荐回答(1个)
回答1:

在代码中加入以下事件代码即可让鼠标滚轮支持VScrollBar:
Private Sub mouse_wheel(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseWheel
If e.Delta = 120 Then
If VScrollBar1.Value - VScrollBar1.SmallChange >= 0 Then
VScrollBar1.Value -= VScrollBar1.SmallChange
ElseIf VScrollBar1.Value - 1 >= 0 Then
VScrollBar1.Value -= 1
End If
Else
If VScrollBar1.Value + VScrollBar1.SmallChange <= VScrollBar1.Maximum Then
VScrollBar1.Value += VScrollBar1.SmallChange
ElseIf VScrollBar1.Value + 1 <= VScrollBar1.Maximum Then
VScrollBar1.Value += 1
End If
End If
End Sub