Thanks for the reply!
I'm not understanding this line:
ContainerOfSomeClass.Add(New SomeClass With {.Label1 = Me.Label1, .Label2 = Me.Label2, .PictureBox = Me.PictureBox1})
my form doesn't have a label1, label2, or picturebox1 so its telling me they dont exist on the form. when i get to "With {." it recognizes the 4 labels & picturebox in my class, but i dont understand why im setting it to "=me.label1" since me.label1 doesn't exist
Here's what I was doing
on my form i have
On my class i haveCode:For i As Integer = 0 to 4 'adds 5 panels ' Call the AddNewPanel Method of MyControlArray MyControlArray.AddNewPanel(dtInfo.Rows(i)("ID"), dtInfo.Rows(i)("Pic"), dtInfo.Rows(i)("First") & " " & dtInfo.Rows(i)("Last"), dtInfo.Rows(i)("Title"), dtInfo.Rows(i)("Address")) panelCount += 1 Next
Code:Public Function AddNewPanel(ByVal ID As Integer, ByVal pic As String, ByVal name As String, ByVal title As String, ByVal add As String) As System.Windows.Forms.Panel 'declare variables Dim aPanel As New System.Windows.Forms.Panel Dim picLogo As New System.Windows.Forms.PictureBox Dim lblName As New System.Windows.Forms.Label Dim lblID As New System.Windows.Forms.Label Dim lblTitle As New System.Windows.Forms.Label Dim lblAdd As New System.Windows.Forms.Label Dim picPath As String = Application.StartupPath & "\" & pic & ".jpg" 'add control properties lblName.Location = New Point(80, 2) lblName.MaximumSize = New Size(220, 20) lblName.Size = New Size(220, 20) lblName.Font = New Font("Microsoft Sans Serif", 9.25, FontStyle.Bold) lblName.Text = name 'etc....... 'add controls to panel aPanel.Controls.Add(picLogo) aPanel.Controls.Add(lblID) aPanel.Controls.Add(lblName) aPanel.Controls.Add(lblTitle) aPanel.Controls.Add(lblAdd) Return aPanel End Function




Reply With Quote