2 Columns of checkboxes. (I am blind to the solution)

martin.s.ransome

Active member
Joined
May 29, 2011
Messages
25
Programming Experience
5-10
I want to create two columns of checkboxes but only the first column is being displayed. Please look at me code and advise where I have erred in my ways and thanks for any assistance rendered:

VB.NET:
    Sub addCheckBoxes()
        Dim chBox1 As New CheckBox
        Dim chBox2 As New CheckBox
        Static x, i As Int32
        Dim intTop1 As Int32 = (x * 24) + 110
        Dim intLeft1 As Int32 = 400
        Dim intTop2 As Int32 = (x * 24) + 110
        Dim intLeft2 As Int32 = 480


        chBox1.Location = New Point(intLeft1, intTop1)
        chBox1.Name = "chkBox_" + i.ToString
        chBox1.Visible = True


        chBox2.Location = New Point(intLeft2, intTop2)
        i = i + 1
        chBox2.Name = "chkBox_" + (i).ToString
        chBox2.Visible = True


        Me.Controls.Add(chBox1)
        Me.Controls.Add(chBox2)


        x = x + 1
        i = i + 1
    End Sub
 
By default checkboxes have a label - set the Text property to "" and the Width property to 15 (the default the designer sets it to when removing label text) and you should see both checkboxes.

Basically an 80 pixel difference was putting your second checkbox under the (blank) label of the first.
 
You should forget pretty much all that code and just use a TableLayoutPanel. Configure it appropriately in the designer and then all the code you need would be:
Me.TableLayoutPanel1.Controls.Add(New CheckBox)
Me.TableLayoutPanel1.Controls.Add(New CheckBox)
 
Back
Top