Search code examples
vb.netlocationlabelgroupbox

Dynamic label won't show in a specified GroupBox


Basically I'm creating Dynamics labels for a groupbox, but it only shows the first 10 I create and the next 10 won't show up. I'm having hard time to figure it out.

Here it's my Method to add the labels on the groupbox:

 Private Sub Create_Numbered_Labels()
    Dim x As Integer

    ''10 First labels

    For x = 0 To 9
        ''Create labels (1 to 10)
        Dim lbl As Label = Custom_Label((x + 1).ToString(), "lblNumber" & (x + 1).ToString(), New Point(6, 48 + (x * 38)))
        ''Add in Groupbox
        grpEssais.Controls.Add(lbl)
    Next

    ''10 next labels

    For x = 10 To 19
        ''Create Labels (11 to 20)
        Dim lbl As Label = Custom_Label((x + 1).ToString(), "lblNumber" & (x + 1).ToString(), New Point(493, 48 + (x * 38)))
        ''Add in GroupBox
        grpEssais.Controls.Add(lbl)
    Next
End Sub

Here is my function Custom_Label()

   Function Custom_Label(Sent_Text As String, Sent_Name As String, Sent_Location As Point) As Label
    ''Instance
    Dim lbl As New Label()

    ''DO NOT MODIFY
    lbl.AutoSize = False
    lbl.Size = New Size(33, 29)
    lbl.TextAlign = ContentAlignment.MiddleCenter
    lbl.BackColor = Color.White


    ''MODIFY WITH PARAMETERS
    lbl.Text = Sent_Text
    lbl.Name = Sent_Name ''LabelName (Sent_Name)-->String
    lbl.Location = Sent_Location ''Location (Sent_Location)-->Point() type

    ''Return the label
    Return lbl
End Function

Solution

  • Sorry Bothering you with this. I found out it was logic error from me, when I was creating the labels I wasn't putting them on the right Location Causing them to be out of the groupbox area.

        Private Sub Create_Numbered_Labels()
        Dim x As Integer
    
        ''10 First labels
    
        For x = 0 To 9
            ''Create labels (1 to 10)
            Dim lbl As Label = Custom_Label((x + 1).ToString(), "lblNumber" & (x + 1).ToString(), New Point(6, 48 + (x * 38)))
            ''Add in Groupbox
            grpEssais.Controls.Add(lbl)
        Next
    
        ''10 next labels
    
        For x = 0 To 9
            ''Create Labels (11 to 20)
            Dim lbl As Label = Custom_Label(((x + 1) + 10).ToString(), "lblNumber" & ((x + 1) + 10).ToString(), New Point(493, 48 + (x * 38)))
            ''Add in GroupBox
            grpEssais.Controls.Add(lbl)
        Next
    End Sub