R
Ron
I want to create 10 buttons on a form at runtime, the code below is
only creating one button labeled 1. Any idea what I am doing wrong?
Public Class Form1
Public code(10) As String
Public buttons(10) As Button
Const buttonwh As Integer = 30
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim i, j, row As Integer
Dim pntcurrent As Point
For i = 0 To 10
j = i Mod 13 + 2
If i = 13 Then
row = 65
End If
pntcurrent = New Point(j + (buttonwh + 8), row)
Call createbuttons(i, pntcurrent)
Next
For k As Integer = 0 To buttons.GetUpperBound(0)
AddHandler buttons(k).Click, AddressOf Button_click
Next
End Sub
Private Sub createbuttons(ByVal i As Integer, _
ByVal pnt As Point)
buttons(i) = New Button
buttons(i).Enabled = True
buttons(i).Visible = True
buttons(i).Text = Convert.ToString(i + 1)
buttons(i).Size = New _
System.Drawing.Size(buttonwh, buttonwh)
buttons(i).Location = pnt
Me.Controls.Add(buttons(i))
End Sub
Private Sub button_click(ByVal sender As System.Object, _
ByVal e As System.EventArgs)
End Sub
End Class
only creating one button labeled 1. Any idea what I am doing wrong?
Public Class Form1
Public code(10) As String
Public buttons(10) As Button
Const buttonwh As Integer = 30
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim i, j, row As Integer
Dim pntcurrent As Point
For i = 0 To 10
j = i Mod 13 + 2
If i = 13 Then
row = 65
End If
pntcurrent = New Point(j + (buttonwh + 8), row)
Call createbuttons(i, pntcurrent)
Next
For k As Integer = 0 To buttons.GetUpperBound(0)
AddHandler buttons(k).Click, AddressOf Button_click
Next
End Sub
Private Sub createbuttons(ByVal i As Integer, _
ByVal pnt As Point)
buttons(i) = New Button
buttons(i).Enabled = True
buttons(i).Visible = True
buttons(i).Text = Convert.ToString(i + 1)
buttons(i).Size = New _
System.Drawing.Size(buttonwh, buttonwh)
buttons(i).Location = pnt
Me.Controls.Add(buttons(i))
End Sub
Private Sub button_click(ByVal sender As System.Object, _
ByVal e As System.EventArgs)
End Sub
End Class