增强VB列表框功能两例
#1?牐牳斜砜蛟黾酉钅坎檎夜δ?
?牐犘陆üこ蹋诖疤迳显黾右桓隽斜砜颉⒁桓鑫谋究颍⑸柚昧斜砜蚴粜裕簃ultiselect=1,添加部分代码:
?牐燩rivate Sub Form_Load()
?牐燚im filenum%, catalog$(99), i%
?牐燙hDir App.Path
?牐燙hDrive App.Path
?牐燜ileName$=“content.txt” '文本文件中含有多条列表框项目
?牐爁ilenum = FreeFile
?牐燨pen FileName$ For Input As #filenum
?牐燚o While Not EOF(filenum)
?牐燣ine Input #filenum,catalog(i)
?牐營f catalog(i)<> “” Then
?牐燣ist1.AddItem catalog(i) '追加列表框项目
?牐燛nd If
?牐爄 = i + 1
?牐燣oop
?牐燙lose #filenum
?牐燛nd Sub
?牐燩rivate Sub Text1_KeyPress(KeyAscii As Integer)??
?牐燚im keyword$,listitem$
?牐燚im locality%
?牐營f KeyAscii = 13 Then '回车查找
?牐爇eyword = RTrim?烲Trim(Text1.Text)??
?牐燜or i = 0 To List1.ListCount - 1
?牐爈istitem = List1.List(i)
?牐爈ocality = InStr(listitem, keyword)
?牐營f locality <> 0 Then
?牐燣ist1.Selected(i) = True
?牐燛nd If
?牐燦ext
?牐燛nd If
?牐燛nd Sub
#1?牐犜黾恿斜砜蛳钅孔远贫δ?
?牐犜谏侠校サ粑谋究颍黾右桓黾剖逼鳎柚眉剖逼魇粜裕篹nabled=false,interval=400;设置列表框属性:multiselect=0。添加有关代码:
?牐燚im n%
?牐燩rivate Sub Form_Load?煟?
?牐牎?
?牐爊 = 1
?牐燛nd Sub
?牐燩rivate Sub List1_Click()'单击列表框项目,焦点自动移动
?牐燭imer1.Enabled = True
?牐燛nd Sub
?牐燩rivate Sub List1_DblClick()'双击后焦点停止移动并执行命令
?牐燭imer1.Enabled = False
?牐燩rint “sample”
?牐燛nd Sub
?牐燩rivate Sub Timer1_Timer()
?牐燣ist1.ListIndex = List1.ListIndex + n '焦点上、下移动
?牐營f List1.ListIndex = List1.ListCount - 1 Then n = -1
?牐營f List1.ListIndex = 0 Then n = 1
?牐燛nd Sub