Getting Attributes of Dynamically Created Controls on a VB Form

asn1981

Active member
Joined
Mar 15, 2005
Messages
38
Programming Experience
Beginner
hi
I am using vb.net to create a form that has several dynamically created labels
the amount of rows for each column may vary on the data

basically what i need to do i get the location values for dynamically created labels as i then wish to add another label directly below this

however as can be seen with my code below if i was to do lblPerson2.location.y then this is just give me the y value for the last lblPerson2 label that was created.

how can i get the location values of the first dynamically created label on the form or any other for that matter

please let me know if it is not to clear what i am trying to achieve.

my code:

VB.NET:
For i = 0 To iCountDS - 1
Dim sDepartment As String = GetSqlData.GetDepartmentFromManager(ds.Tables(0).Rows(i).Item(0))
 
'Dim dsEmp As DataSet = GetSqlData.GetAllEmpsforDepartment(sDepartment)
Dim dsemp As DataSet = GetSqlData.GetEmployeesAtLevel(EmpTypeLevel, sDepartment)
 
Dim z As Integer
iY = iYTemp
Dim iCountDSEmp As Integer = dsemp.Tables(0).Rows.Count - 1
For z = 0 To iCountDSEmp
iY = iY + iRowGap
'create a new label for a person to add to the form
Dim lblPerson2 As New Label
lblPerson2.Text = dsemp.Tables(0).Rows(z).Item(0)
lblPerson2.BackColor = BackColor.RoyalBlue()
lblPerson2.Width = 100
lblPerson2.Height = 28
lblPerson2.TextAlign = ContentAlignment.MiddleCenter
'position the label
lblPerson2.Location = New Point((iX + iXSpacer) * (i + 1), iY)
Me.Controls.Add(lblPerson2)
 
If Not z = iCountDSEmp Then
xPicBox = ((iX + iXSpacer) * (i + 1)) + (lblPerson2.Width / 2)
yPicBox = iY + lblPerson2.Height
DoVertLine(xPicBox, yPicBox)
End If
'Form.ActiveForm.Size = New Size((lblPerson2.Location.X + lblPerson2.Width) + (iX + iXSpacer), (lblPerson2.Location.Y + 200))
Next
Next
 
Last edited by a moderator:
Back
Top