Option Strict On 'VisualBsic2008 Public Class Form1 'ボタンコントロール配列のフィールドを作成 Private testButtons() As System.Windows.Forms.Button Private Sub Form1_Load(ByVal sender As Object, _ ByVal e As System.EventArgs) Handles MyBase.Load Me.testButtons = New System.Windows.Forms.Button(49) {} Me.SuspendLayout() Dim i As Integer Dim c, d As Integer c = 0 : d = 0 For i = 0 To Me.testButtons.Length - 1 Me.testButtons(i) = New System.Windows.Forms.Button Me.testButtons(i).Name = "Button" + i.ToString() Me.testButtons(i).Text = i.ToString() Me.testButtons(i).Size = New Size(30, 30) Me.testButtons(i).Location = New Point(c * 30, 10 + d) c += 1 If c = 9 Then c = 0 : d += 30 End If AddHandler Me.testButtons(i).Click, _ AddressOf Me.testButtons_Click Next i Me.Controls.AddRange(Me.testButtons) Me.ResumeLayout(False) End Sub Private Sub testButtons_Click(ByVal sender As Object, _ ByVal e As EventArgs) MessageBox.Show(CType(sender, System.Windows.Forms.Button).Name) End Sub End Class