我不知道是否有一個原因,你是這樣做的兩個步驟。
嘗試是這樣的:根據您的意見
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))。它給出了錯誤的輸出。 –