Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2008/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net 与费舍尔一起洗牌–;耶茨_Vb.net - Fatal编程技术网

Vb.net 与费舍尔一起洗牌–;耶茨

Vb.net 与费舍尔一起洗牌–;耶茨,vb.net,Vb.net,我的程序有问题,我正在尝试洗牌一堆图片框,然后解开它们。我尝试了费舍尔-耶茨洗牌,但没有运气。请给我举个例子 我使用的是一个标准表单,上面有一个面板、一个图片框、一个文本框和三个按钮 Imports System.Drawing Imports System.Windows.Forms Public Class Form1 Private Sub TestSplit() Dim fr_bm As New Bitmap(PictureBox1.Image) Dim wid As

我的程序有问题,我正在尝试洗牌一堆图片框,然后解开它们。我尝试了费舍尔-耶茨洗牌,但没有运气。请给我举个例子

我使用的是一个标准表单,上面有一个面板、一个图片框、一个文本框和三个按钮

Imports System.Drawing
Imports System.Windows.Forms

Public Class Form1
Private Sub TestSplit()
    Dim fr_bm As New Bitmap(PictureBox1.Image)
    Dim wid As Integer = PictureBox1.Image.Width \ 8
    Dim hgt As Integer = PictureBox1.Image.Height \ 6
    Dim colnum, rownum As Integer
    For rownum = 0 To 5
        For colnum = 0 To 7
            Dim to_bm As New Bitmap(PictureBox1.Image)
            Dim gr As Graphics = Graphics.FromImage(to_bm)
            Dim fr_rect As New Rectangle(colnum * wid, rownum * hgt, hgt, hgt)
            Dim to_rect As New Rectangle(0, 0, wid, hgt)
            gr.DrawImage(fr_bm, to_rect, fr_rect, GraphicsUnit.Pixel)
            Dim MyPictureBox As New PictureBox
            MyPictureBox.Height = hgt
            MyPictureBox.Width = wid
            MyPictureBox.Left = colnum * hgt
            MyPictureBox.Top = rownum * wid
            MyPictureBox.BorderStyle = BorderStyle.FixedSingle
            'MyPictureBox.SizeMode = PictureBoxSizeMode.Normal
            MyPictureBox.Image = to_bm
            MyPictureBox.Name = "PicBox" & rownum & colnum
            Panel1.Controls.Add(MyPictureBox)
        Next
    Next
End Sub
Private Sub OpenButt_Click(sender As System.Object, e As System.EventArgs) Handles OpenButt.Click
    Using O As New OpenFileDialog With {.Filter = "(Image Files)|*.jpg;*.png;*.bmp;*.gif;*.ico|Jpg, | *.jpg|Png, | *.png|Bmp, | *.bmp|Gif, | *.gif|Ico | *.ico", .Multiselect = False, .Title = "Select image"}
        If O.ShowDialog = 1 Then
            TextBox1.Text = O.FileName
            PictureBox1.Image = Image.FromFile(O.FileName)
            PictureBox1.SizeMode = PictureBoxSizeMode.Zoom
        Else
            TextBox1.Clear()
        End If

    End Using
End Sub

Private Sub BoardButt_Click(sender As System.Object, e As System.EventArgs) Handles BoardButt.Click
    TestSplit()
End Sub

Private Sub ShuffleButt_Click(sender As System.Object, e As System.EventArgs) Handles ShuffleButt.Click

End Sub
End Class

在表单和按钮上放置两个列表框(最好在中间)

左侧的Listbox1是原始排序列表 右侧的Listbox2是原始排序列表的副本

单击按钮,listbox2中的文件将被洗牌

代码如下

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click

    Dim i As Integer
    Dim j As Integer
    '
    ListBox2.Items(0) = ListBox1.Items(0)
    For i = 1 To ListBox1.Items.Count - 1
        j = Int(Rnd(1) * i)
        ListBox2.Items(i) = ListBox2.Items(j)
        ListBox2.Items(j) = ListBox1.Items(i)
    Next

End Sub

Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load

    Dim counta As Integer
    '
    For counta = 0 To 39
        ListBox1.Items.Add("image" & counta & ".gif")
        ListBox2.Items.Add("image" & counta & ".gif")
    Next
    counta = Nothing

End Sub
参考:由内而外洗牌

既然这是用VB.NET编写的,为什么还要将其标记为C?你说过你尝试Fisher Yates时运气不佳。你试过的代码在哪里?结果出了什么问题?你说的“释放它们”是什么意思?