我不知道是否有一个原因,你是这样做的两个步骤。
尝试是这样的:根据您的意见
Private btnArray As New List(Of Button)
For i As Integer = 0 To 10
Dim btn As New Button
With btn
.Tag = i ' Tag of button
.Width = 40 ' Width of button
.Height = 40
.Text = Chr(i + 48)
End With
btnArray.Insert(i, btn)
'FlowLayoutPanel1.Controls.Add(btnArray(i)) 'It works also
FlowLayoutPanel1.Controls.Add(btn)
AddHandler .Click, AddressOf Me.GenericClickHandler
Next i
:
Private btnArray As New List(Of Button)
Private btnShuffleArray As New List(Of Button)
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
For i As Integer = 0 To 10
' Initialize one variable
Dim btn As New Button
With btn
.Tag = i ' Tag of button
.Width = 40 ' Width of button
.Height = 40
.Text = Chr(i + 48)
btnArray.Insert(i, btn)
' FlowLayoutPanel1.Controls.Add(btnArray(i))
'AddHandler .Click, AddressOf Me.GenericClickHandler
End With
Next i
'Randomize the list
Dim rand As New Random
Dim index As Integer
While btnArray.Count > 0
index = rand.Next(0, btnArray.Count)
btnShuffleArray.Add(btnArray(index))
btnArray.RemoveAt(index)
End While
For i = 0 To 10
FlowLayoutPanel1.Controls.Add(btnShuffleArray(i))
Next
End Sub
问题是什么错误? – Nianios
Dim r As New Random Dim out =(from b在btnArray Order by r.Next选择b).ToArray()我已经这样做了洗牌ARRAY,但它从不在显示面板上显示整个9个按钮。它只显示3/4/5或表单上的空白按钮。我想我错了代码。我正在像这样做flowlayoutpanel1.controls.add(out(n))。它给出了错误的输出。 –