注册 登录
编程论坛 VB6论坛

请教, 有没有可能让一个滚动条控制所有 listbox?

VBLeah 发布于 2018-05-28 09:38, 1541 次点击

放一个vscrollbar, 控制listbox 1 2 3 让他们同步滚动, 该怎么实现? 求大神指点
3 回复
#2
wds12018-05-28 13:22
Private Sub Form_Load()
File1.Path = "c:\windows"
File2.Path = "C:\Windows\SysWOW64"
File3.Path = "c:\windows\system32"
VScroll1.Max = 100
VScroll1.Min = 1
VScroll1.LargeChange = 1
VScroll1.SmallChange = 1
End Sub

Private Sub VScroll1_Change()
 temp1 = VScroll1.Value
 t1 = Int(File1.ListCount * temp1 / 100) - 1
 temp1 = VScroll1.Value
 t2 = Int(File2.ListCount * temp1 / 100) - 1
 temp1 = VScroll1.Value
 t3 = Int(File3.ListCount * temp1 / 100) - 1
 File1.ListIndex = t1
 File2.ListIndex = t2
 File3.ListIndex = t3
End Sub

[此贴子已经被作者于2018-5-28 13:31编辑过]

#3
ZHRXJR2018-05-28 21:08
只有本站会员才能查看附件,请 登录

程序代码:

Private Sub Form_Load()
For I = 0 To 119
List1.AddItem I + 1
List2.AddItem I + 1
List3.AddItem I + 1
Next I
VScroll1.Max = 120
VScroll1.Min = 1
End Sub

Private Sub VScroll1_Change()
Dim APST As Single

 APST = VScroll1.Value

 List1.ListIndex = Int(List1.ListCount * APST / 100) - 1

 List2.ListIndex = Int(List2.ListCount * APST / 100) - 1

 List3.ListIndex = Int(List3.ListCount * APST / 100) - 1
End Sub

你要的是这个吧?
回复 wmf2014
可能吧,只考虑了相同的情况。如果情况不同,估计加判断加应该可以吧!

[此贴子已经被作者于2018-5-29 12:17编辑过]

#4
wmf20142018-05-29 10:51
回复 3楼 ZHRXJR
拖到最后出现错误,另外没有考虑各个listcount不一样,再就是应该用topindex属性合理些,用listindex改变list原有选择了。因此你这个代码不具备实用性。
1