Option ExplicitConst SBS_HORZ = 0 Const SBS_VERT = 1 Private Const SIF_RANGE = &H1 Private Const SIF_PAGE = &H2 Private Const SIF_POS = &H4 Private Const SIF_DISABLENOSCROLL = &H8 Private Const SIF_TRACKPOS = &H10 Private Const SIF_ALL = (SIF_RANGE Or SIF_PAGE Or SIF_POS Or SIF_TRACKPOS)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 Private Declare Function GetScrollInfo Lib "user32" (ByVal hWnd As Long, ByVal n As Long, lpScrollInfo As SCROLLINFO) As LongPrivate Sub MSFlexGrid1_Scroll() Dim SInfo As SCROLLINFO SInfo.cbSize = LenB(SInfo) SInfo.fMask = SIF_ALL Call GetScrollInfo(Me.MSFlexGrid1.hWnd, SBS_VERT, SInfo) Debug.Print SInfo.nPos End Sub
你的textbox是在点击网络时定的位吧? 那么在click事件中取得当时msflexgrid的toprow与row值,row-toprow就是你当前在网格上显示的行数假设为NRow scroll事件里再取topr+Nrow,就是滚动后应该显示的行数了 如: dim nRow as integer private sub msflexgrid_click() nrow=msflexgrid.row-msflexgrid.toprow end sub private sub msflexgrid_scroll() msflexgrid.row=mflexgrid.toprow+nrow text1.move msflexgrid.left+msflexgrid.cellleft,msflexgrid.top+msflexgrid.cellTop, msflexgrid.cellwidth,msflexgrid.cellheight end sub
Const SBS_VERT = 1
Private Const SIF_RANGE = &H1
Private Const SIF_PAGE = &H2
Private Const SIF_POS = &H4
Private Const SIF_DISABLENOSCROLL = &H8
Private Const SIF_TRACKPOS = &H10
Private Const SIF_ALL = (SIF_RANGE Or SIF_PAGE Or SIF_POS Or SIF_TRACKPOS)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
Private Declare Function GetScrollInfo Lib "user32" (ByVal hWnd As Long, ByVal n As Long, lpScrollInfo As SCROLLINFO) As LongPrivate Sub MSFlexGrid1_Scroll()
Dim SInfo As SCROLLINFO
SInfo.cbSize = LenB(SInfo)
SInfo.fMask = SIF_ALL
Call GetScrollInfo(Me.MSFlexGrid1.hWnd, SBS_VERT, SInfo)
Debug.Print SInfo.nPos
End Sub
那么在click事件中取得当时msflexgrid的toprow与row值,row-toprow就是你当前在网格上显示的行数假设为NRow
scroll事件里再取topr+Nrow,就是滚动后应该显示的行数了
如:
dim nRow as integer
private sub msflexgrid_click()
nrow=msflexgrid.row-msflexgrid.toprow
end sub
private sub msflexgrid_scroll()
msflexgrid.row=mflexgrid.toprow+nrow
text1.move msflexgrid.left+msflexgrid.cellleft,msflexgrid.top+msflexgrid.cellTop,
msflexgrid.cellwidth,msflexgrid.cellheight
end sub
我已成功解决