如何通过mousemove移动滚动条
当控件里的图放大一定比例是,会自动有滚动条,此时我想通过mousemove移动滚动条
但没效果,代码如下,各位帮忙看看问题在哪里,tks
代码如下:
Private Sub ImgEdit1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)mousemove 滚动条
If Button = 1 Then
bx = X
by = Y
Startmove = True
End If
End Sub
Private Sub ImgEdit1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
'On Error Resume Next
If Y > ImgEdit1.Top And Y < ImgEdit1.Top + ImgEdit1.Height And ImgEdit1.Height > Screen.Height - 1200 Then '如果鼠标在控件内
VScroll1.Value = (Y - ImgEdit1.Top) / (ImgEdit1.Height) * 100
End If
If X > ImgEdit1.Left And X < ImgEdit1.Left + ImgEdit1.Width And ImgEdit1.Height > Screen.Height - 1200 Then
HScroll1.Value = (X - ImgEdit1.Left) / (ImgEdit1.Width) * 100
End If
If Startmove Then HScroll1.Value + X - bx, VScroll1.Value + Y - by
End Sub
Private Type SCROLLINFO
cbSize As Long
fMask As Long
nMin As Long
nMax As Long
nPage As Long
nPos As Long
nTrackPos As Long
End Type
‘如果你想得到滚动条当前的值可以这么做:
Dim Scroll As SCROLLINFO
Scroll.cbSize = LenB(Scroll.cbSize)
Scroll.fMask = SIF_ALL
GetScrollInfo ImgEdit1.hWnd, SB_VERT, Scroll
Msgbox Scroll.nPos & "/" & Scroll.nMax
' 下面设置滚动条到最后的位置
Scroll.nPos = Scroll.nMax
SetScrollInfo ImgEdit1.hWnd, SB_VERT, Scroll, True