你如何在三个不同的列表框中随机播放项目。 [英] How do you shuffle items in three different list boxes.

查看:60
本文介绍了你如何在三个不同的列表框中随机播放项目。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个代码只调整一个列表框,但是我希望它能够将这三个列表框混乱。我该怎么做?

I have a code that shuffles only one listbox but i want it to shuffle all three. How do i do that?

推荐答案

为每个ListBox调用上面的Sub(更新后的代码):

Call the above Sub for each ListBox (updated code):

ShuffleList(ListBox1)
ShuffleList(ListBox2)
ShuffleList(ListBox3)

    Private Sub ShuffleList(ByVal Listbox As System.Windows.Forms.ListBox)

        Dim Random As New System.Random

        Listbox.BeginUpdate()

        Dim ArrayList As New System.Collections.ArrayList(Listbox.Items)

        Listbox.Items.Clear()

        While ArrayList.Count > 0

            Dim Index As System.Int32 = Random.Next(0, ArrayList.Count)

            Listbox.Items.Add(ArrayList(Index))

            ArrayList.RemoveAt(Index)

        End While

        Listbox.EndUpdate()

    End Sub


这篇关于你如何在三个不同的列表框中随机播放项目。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆