怎么让VB滚动条控件跟着鼠标滚轴移动
2个回答
推荐于2018-03-20
展开全部
添加一个窗体,在窗体上添加一个垂直滚动条,名字就默认即可,然后粘贴如下代码:
Private Sub Form_Load()
OldProcAddr = SetWindowLong(Me.hwnd, GWL_WNDPROC, AddressOf MyWinProc)
End Sub
然后添加一个模块,粘贴如下代码:
Public Const GWL_WNDPROC = (-4)
Public Const WM_MOUSEWHEEL = &H20A
Public OldProcAddr As Long
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Function MyWinProc(ByVal hwnd As Long, ByVal msg As Long, ByVal wp As Long, ByVal lp As Long) As Long
If msg <> WM_MOUSEWHEEL Then
MyWinProc = CallWindowProc(OldProcAddr, hwnd, msg, wp, lp)
Else
Debug.Print msg
Dim s As String
s = Hex(wp)
If Len(s) < 8 Then s = String(8 - Len(s), "0") & s
Dim zDelta As Long
zDelta = CInt("&h" & Left(s, 4)) * (-1)
If Form1.VScroll1.Value + zDelta < Form1.VScroll1.Min Then
Form1.VScroll1.Value = Form1.VScroll1.Min
ElseIf Form1.VScroll1.Value + zDelta > Form1.VScroll1.Max Then
Form1.VScroll1.Value = Form1.VScroll1.Max
Else
Form1.VScroll1.Value = Form1.VScroll1.Value + zDelta
End If
End If
End Function
注意的是所有东西不能有任何差错,否则VB会挂掉,不明白的百度HI我
Private Sub Form_Load()
OldProcAddr = SetWindowLong(Me.hwnd, GWL_WNDPROC, AddressOf MyWinProc)
End Sub
然后添加一个模块,粘贴如下代码:
Public Const GWL_WNDPROC = (-4)
Public Const WM_MOUSEWHEEL = &H20A
Public OldProcAddr As Long
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Function MyWinProc(ByVal hwnd As Long, ByVal msg As Long, ByVal wp As Long, ByVal lp As Long) As Long
If msg <> WM_MOUSEWHEEL Then
MyWinProc = CallWindowProc(OldProcAddr, hwnd, msg, wp, lp)
Else
Debug.Print msg
Dim s As String
s = Hex(wp)
If Len(s) < 8 Then s = String(8 - Len(s), "0") & s
Dim zDelta As Long
zDelta = CInt("&h" & Left(s, 4)) * (-1)
If Form1.VScroll1.Value + zDelta < Form1.VScroll1.Min Then
Form1.VScroll1.Value = Form1.VScroll1.Min
ElseIf Form1.VScroll1.Value + zDelta > Form1.VScroll1.Max Then
Form1.VScroll1.Value = Form1.VScroll1.Max
Else
Form1.VScroll1.Value = Form1.VScroll1.Value + zDelta
End If
End If
End Function
注意的是所有东西不能有任何差错,否则VB会挂掉,不明白的百度HI我
展开全部
1、滚动条分为水平滚动条(HSCROLLBAR)和垂直滚动条(VSCROLLBAR)两种,可以作为输入设备或者速度、数量的指示器来使用.
2、基本属性:object.max[=value],object.min[=value],最大最小范围
object.value[=value],用来返回你滑动滚动条时所在位置对应的值
3、基本方法 drag 用于空间的开始、结束火取消拖动操作
move 移动控件
setfocus 将焦点移动至指定的控件
refresh 强制重绘控件
zorder 将控件放置在其图层的z-顺序的前端或者后端
4、基本事件 change
dragdrop
dragover
gotfocus
lostfocus
keydown
keyup
keypress
scroll
具体的可以看MSDN
2、基本属性:object.max[=value],object.min[=value],最大最小范围
object.value[=value],用来返回你滑动滚动条时所在位置对应的值
3、基本方法 drag 用于空间的开始、结束火取消拖动操作
move 移动控件
setfocus 将焦点移动至指定的控件
refresh 强制重绘控件
zorder 将控件放置在其图层的z-顺序的前端或者后端
4、基本事件 change
dragdrop
dragover
gotfocus
lostfocus
keydown
keyup
keypress
scroll
具体的可以看MSDN
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询