‘DataGrid的鼠標(biāo)滾動(dòng)操作在另一篇博客里面
‘在VB中,MsFlexGrid和DataGrid等控件本來(lái)不支持鼠標(biāo)的滾動(dòng)操作,但是人性化的設(shè)計(jì)要求希望這些控件能支持鼠標(biāo)的各項(xiàng)操作。但是這些控件本身并不自帶鼠標(biāo)的支持參數(shù),必須要自己添加相應(yīng)的代碼。
‘本代碼需要引用Microsoft FlexGrid Control 6.0
Private Const PM_REMOVE = &H1
Private Type POINTAPI
x As Long
y As Long
End Type
Private Type Msg
hWnd As Long
Message As Long
wParam As Long
lParam As Long
time As Long
pt As POINTAPI
End Type
Private Declare Function PeekMessage Lib "user32" Alias "PeekMessageA" _
(lpMsg As Msg, _
ByVal hWnd As Long, _
ByVal wMsgFilterMin As Long, _
ByVal wMsgFilterMax As Long, _
ByVal wRemoveMsg As Long) As Long
Private Declare Function WaitMessage Lib "user32" () As Long
Private bCancel As Boolean
Private Const WM_MOUSEWHEEL = 522
Private Sub ProcessMessages()
Dim Message As Msg
Do While Not bCancel
WaitMessage ‘等待消息
If PeekMessage(Message, MSFlexGrid1.hWnd, WM_MOUSEWHEEL, WM_MOUSEWHEEL, PM_REMOVE) Then ‘...when the mousewheel is used...
If Message.wParam < 0 Then ‘向上滾動(dòng)
‘Me.Top = Me.Top + 240
If MSFlexGrid1.TopRow < MSFlexGrid1.Rows Then
MSFlexGrid1.TopRow = MSFlexGrid1.TopRow + 1
End If
Else ‘向下滾動(dòng)
If MSFlexGrid1.TopRow > 1 Then
MSFlexGrid1.TopRow = MSFlexGrid1.TopRow - 1
End If
End If
End If
DoEvents
Loop
End Sub
Private Sub Form_Unload(Cancel As Integer)
bCancel = True
End Sub
Private Sub Form_Load()
For i = 1 To 25
MSFlexGrid1.AddItem i
Next i
Me.AutoRedraw = True
Me.Print "請(qǐng)使用鼠標(biāo)滾輪改變本窗體的位置。"
Me.Show
ProcessMessages
End Sub
本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶(hù)發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)
點(diǎn)擊舉報(bào)。