Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1752401
  • 博文数量: 600
  • 博客积分: 10581
  • 博客等级: 上将
  • 技术积分: 6205
  • 用 户 组: 普通用户
  • 注册时间: 2008-11-06 10:13
文章分类
文章存档

2016年(2)

2015年(9)

2014年(8)

2013年(5)

2012年(8)

2011年(36)

2010年(34)

2009年(451)

2008年(47)

分类:

2009-10-11 13:52:07

来源:MSDN   Thomasaria

使List1项目的移动、选取,影响List2项目的动、选取

需:两个ListBox,一个Timer
但这是vb4.0的作法,在vb5.0时,可以由Thomasaria 提供的简易作法完成

Private Sub List1_Scroll(Index As Integer)
'按卷动轴时list项目位置同步
List2.TopIndex = List1.TopIndex
End Sub

Private Sub List2_Scroll(Index As Integer)
'按卷动轴时list项目位置同步
List1.TopIndex = List2.TopIndex
End Sub


Option Explicit

Sub Form_Load()
      'Initialize two list boxes with the alphabet
      Dim i As Long
      For i = 1 To 26
	 List1.AddItem Chr$(i + 64)
      Next i
      For i = 1 To 26
	 List2.AddItem Chr$(i + 64)
      Next i
      Timer1.Interval = 1
      Timer1.Enabled = True
End Sub

Sub Timer1_Timer()
      Dim TopIndex_List1 As Long
      Static PrevTI_List1
      'Get the index for the first item in the visible list
      TopIndex_List1 = List1.TopIndex
      'See if the top index has changed
      If TopIndex_List1 <> PrevTI_List1 Then
	 'Set the top index of List2 equal to List1 so that the list boxes
	 'scroll to the same relative position
	 List2.TopIndex = TopIndex_List1
	 'Keep track of the current top index
	 PrevTI_List1 = TopIndex_List1
      End If
      'Select the item in the same relative position in both list boxes
      If List1.ListIndex <> List2.ListIndex Then
	 List2.ListIndex = List1.ListIndex
      End If
End Sub
 
阅读(1056) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~