假如一个listbox中的每项是一个网址,请问VB高手,怎样遍历listbox中的每项,遍历到该项时,显示在textbox

2025-04-09 09:16:43
推荐回答(5个)
回答1:

Private Sub Command1_Click()
Timer1.Enabled = Not Timer1.Enabled
End Sub

Private Sub Form_Load()
Timer1.Enabled = False
Timer1.Interval = 500
End Sub

Private Sub Timer1_Timer()
List1.ListIndex = List1.ListIndex + 1
Text1 = List1.List(List1.ListIndex)
If List1.ListIndex = List1.ListCount - 1 Then Timer1.Enabled = False
End Sub

回答2:

For i = 0 To List1.ListCount - 1
text1.Text = text1.Text & List1.List(i) & vbCrLf
Next

回答3:

For i = 0 To List1.ListCount - 1
if list1(i)="xxxxx" then
text1.text = list1(i)
endif
Next

回答4:

textbox???不是VB6啊??

回答5:

'动态添加控件测试,呵呵。
'窗体上不能有下列控件的名称。
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Dim WithEvents cX As CommandButton
Dim WithEvents cXS As CommandButton
Dim WithEvents cM As Timer
Dim cT As TextBox, WithEvents cL As ListBox
Private Sub Form_Load()
Caption = "通过Timer, 遍历listbox"
Width = 6000: Height = 3600
Set cX = Controls.Add("VB.CommandButton", "cX")
cX.Visible = True: cX.Width = 1600: cX.Left = Width - 1800
cX.Caption = "遍历listbo&x"
Set cXS = Controls.Add("VB.CommandButton", "cXS")
cXS.Visible = True: cXS.Width = 1600: cXS.Left = Width - 1800
cXS.Top = 600
cXS.Caption = "停止或开始"
Set cL = Controls.Add("vb.listbox", "cL")
cL.Visible = True: cL.Width = 4100: cL.Height = 2600
Set cT = Controls.Add("vb.textbox", "cT")
cT.Visible = True: cT.Width = 5800: cT.Top = 2700
cT.Height = 300: cT.Text = "动态控件测试..."
Set cM = Controls.Add("vb.timer", "cM")
cM.Enabled = True: cM.Interval = 1000
For i = 0 To 1000
cL.AddItem "http://zhidao.baidu.com/question/24018" & 4892 + i & ".html"
Next
End Sub
Private Sub cM_Timer()
Static iIndex%
iIndex = (iIndex + 1) Mod cL.ListCount
cT.Text = cL.List(iIndex)
End Sub
Private Sub cX_Click()
If cT.Text <> "" Then ShellExecute 0, "open", cT.Text, "", "", 1
Caption = cT.Text
End Sub
Private Sub cXS_Click()
cM.Enabled = Not cM.Enabled
End Sub
Private Sub cL_Click()
cM.Enabled = False
cT.Text = cL.List(cL.ListIndex)
End Sub
Private Sub cL_DblClick()
ShellExecute 0, "open", cL.List(cL.ListIndex), "", "", 1
End Sub