I am trying to figure out how to go about creating dynamic checkboxes on my form when I do not know exactly how many boxes I will need.
The problem is that I do not know how to DIM more than one object. This is my code for creating one checkbox
Dim checkBox As New CheckBox()
Form1.Controls.Add(checkBox)
checkBox.Location = New Point(10, 10)
checkBox.Text = "testing"
checkBox.Checked = True
checkBox.Size = New Size(100, 20)
It works just fine but i am unable to add more than one checkBox without having to do this:
Dim checkBox As New CheckBox()
Dim checkBox2 As New CheckBox()
Form1.Controls.Add(checkBox)
checkBox.Location = New Point(10, 10)
checkBox.Text = "testing"
checkBox.Checked = True
checkBox.Size = New Size(100, 20)
Form1.Controls.Add(checkBox2)
checkBox2.Location = New Point(40, 10)
checkBox2.Text = "testing2"
checkBox2.Checked = True
checkBox2.Size = New Size(100, 20)
etc…
Is there a way to dim more than 1 checkbox instead of having to write multiple dim statements for each checkBoxe?
Sorry maybe i should say this..
I’m looking to do something like this:
dim checkBox() as CheckBox
do until i = 50
Form1.Controls.Add(checkBox(i))
checkBox(i).Location = New Point(10, 10)
checkBox(i).Text = "testing " & i
checkBox(i).Checked = True
checkBox(i).Size = New Size(100, 20)
i += 1
loop
It seems like the only items that are different and not calculated between the
CheckBoxinstances is the text. If so then you could just use the following code to add a set ofCheckBoxinstances based off of a list ofString‘s.