Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim lb As Object
Dim i As Integer = 0
For Each lb In Me.ListBox1.Items
If CStr(lb).Equals(Me.TextBox1.Text) Then
MessageBox.Show("相同:" & Me.TextBox1.Text & " " & CStr(lb))
Me.ListBox1.Focus() '獲取焦點
Exit For
End If
i += 1
Next
Me.ListBox1.SetSelected(i, True)
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.TextBox1.Text = "test"
With Me.ListBox1.Items
.Add("1")
.Add("test")
.Add("test1")
.Add("3")
End With
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim lb As Object
For Each lb In Me.ListBox1.Items
If CStr(lb).Equals(Me.TextBox1.Text) Then
MessageBox.Show("相同:" & Me.TextBox1.Text & " " & CStr(lb))
End If
Next
End Sub