I'm trying to create multiple labels in different panels, but it keeps creating only one panel.
Here is my code
Dim i As Integer = 0
For i = 0 To 7
Dim lbl As New Label() With
{
.Text = "Suppliant Name:",
.Location = New Point(117, 10 * 1),
.Height = 15,
.Width = 95}
req1.Controls.Add(lbl)
req2.Controls.Add(lbl)
req3.Controls.Add(lbl)
req4.Controls.Add(lbl)
req5.Controls.Add(lbl)
req6.Controls.Add(lbl)
req7.Controls.Add(lbl)
Next
End Sub
CodePudding user response:
Private Sub Add
Dim i As Integer = 0
For i = 0 To 7
AddlbltoPanel(req1)
AddlbltoPanel(req2)
AddlbltoPanel(req3)
AddlbltoPanel(req4)
AddlbltoPanel(req5)
AddlbltoPanel(req6)
AddlbltoPanel(req7)
Next
End Sub
Private Sub AddlbltoPanel(ByVal req as Panel)
'if it doesnt work with byval then check with byref
Dim lbl As New Label
lbl.Text = "Suppliant Name:"
lbl.Location = New Point(117, 10 * 1)
lbl.Height = 15
lbl.Width = 95
req.Controls.Add(lbl)
Me.SuspendLayout()
End Sub
I assume req* are your panels, try above code