如何从Visual Basic中的列表框中选择随机项目

时间:2019-02-10 08:52:23

标签: vb.net visual-studio random listbox listboxitem

我该如何尝试从列表框中选择一个随机项目。

logging.config.dictConfig(LOGGING)

当我在一个消息框中显示所选择的项目时,它会弹出2个消息框。每个消息框显示一个不同的项目。 示例:第一个消息框显示C:\ test \ blab.mp3 第二个显示C:\ test \ bleasds.mp3

1 个答案:

答案 0 :(得分:0)

您可以尝试

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Dim currentTrack As Integer, temp As Integer, gen As Random = New Random()
    Do
        temp = gen.Next(0, listTracks.Items.Count)
        currentTrack = temp
        Dim result1 As DialogResult = MessageBox.Show(listTracks.Items(currentTrack).ToString + vbNewLine + "Play ?",
                                                  "Play", MessageBoxButtons.YesNo)
        If result1 = DialogResult.Yes Then
            AxWindowsMediaPlayer2.URL = listTracks.Items(currentTrack).ToString
        Else
            Exit Do
        End If
    Loop
End Sub