新建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