查看: 255  |  回复: 0
VB6 同时卷动二个列表框
楼主
发表于 2023年5月7日 16:05

新建From1(窗体),新建List1到2(ListBox),代码:

'To synchronise the scrolling to two listboxes use the following routines:
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
'Purpose     :  Synchronises the scrolling of two listboxes
'Inputs      :  lhwndMasterListbox              The handle to the listbox with the focus.
'               lhwndSlaveListbox               The handle to the listbox which is to
'                                               follow the scrolling of the master listbox.
'Outputs     :  On successful returns zero
Function ListboxSynchronise(lhwndMasterListbox As Long, lhwndSlaveListbox As Long) As Long
    Const LB_GETTOPINDEX = &H18E, LB_SETTOPINDEX = &H197
    ListboxSynchronise = SendMessage(lhwndSlaveListbox, LB_SETTOPINDEX, SendMessage(lhwndMasterListbox, LB_GETTOPINDEX, 0&, 0&), 0&)
End Function

'Demonstration routines.
'Place inside a form containing two listboxes.
Private Sub List1_Scroll()
    ListboxSynchronise Me.List1.hwnd, Me.List2.hwnd
End Sub

Private Sub List2_Scroll()
    ListboxSynchronise Me.List2.hwnd, Me.List1.hwnd
End Sub

Private Sub Form_Load()
    Dim lThisRow As Long
    For lThisRow = lThisRow To 50
        List1.AddItem "Item " & CStr(lThisRow)
        List2.AddItem "Item " & CStr(lThisRow)
    Next
End Sub


您需要登录后才可以回帖 登录 | 立即注册
【本版规则】请勿发表违反国家法律的内容,否则会被冻结账号和删贴。
用户名: 立即注册
密码:
2020-2024 MaNongKu.com