1 2 3 | Private Sub btnChange_Click(sender As Object, e As EventArgs) Handles btnChange.Click ListBox1.Items.AddRange(RandomSort(ListBox1).ToArray) End Sub |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | Private Function RandomSort(lst As ListBox) As ArrayList Dim sortedList As ArrayList = New ArrayList() Dim generator As Random = New Random() Dim aryInfo As New ArrayList aryInfo.AddRange(lst.Items) lst.Items.Clear() Do While aryInfo.Count > 0 Dim position As Integer = generator.Next(aryInfo.Count) sortedList.Add(aryInfo(position)) aryInfo.RemoveAt(position) Loop Return sortedList End Function |
沒有留言:
張貼留言