I am not entirely sure what you are trying to achieve and using a class to display a control dynamically with set properties means you limiting yourself to a single instance of that control. Any additional calls to that class will place the next panel on top of the exiting one, if there is already another panel.
If I am not mistaken you can do the same with the following code while you can set the properties separately for each new dynamically added panel control you add the the parent panel.
Here is an example of creating a Picturebox dynamically for each image file in a folder. The code also uses AddHandler for event that can be issued on the Picturebox, like a Click event. The code also controls the placement of each newly added Picturebox and sets the properties for each Picturebox. The mechanics / concept remains the same for any control you add to a form or existing parent control.
Private Sub btnLoadImage_Click(sender As System.Object, e As System.EventArgs) Handles btnLoadImage.Click
Dim Left As Integer = 12
Dim Top As Integer = 0
Dim picBox As PictureBox
pgbImagesLoaded.Value = 0
Me.Cursor = Cursors.WaitCursor
Try
If System.IO.Directory.GetFiles(fbdGetImagesOnDisk.SelectedPath).Length - 1 < 1 Then
MsgBox("No images were found in the selected folder.", MsgBoxStyle.Information)
Me.Cursor = Cursors.Arrow
Return
End If
pgbImagesLoaded.Maximum = System.IO.Directory.GetFiles(fbdGetImagesOnDisk.SelectedPath).Length - 1
lblFilesProcessed.Text = "0/" & pgbImagesLoaded.Maximum
For Each imgFile As String In Directory.GetFiles(fbdGetImagesOnDisk.SelectedPath)
Dim fs As System.IO.FileStream
imgInfo = New FileInfo(imgFile)
If myext.Contains(LCase(imgInfo.Extension)) Then
picBox = New PictureBox()
fs = New System.IO.FileStream(imgInfo.FullName, IO.FileMode.Open, IO.FileAccess.Read)
picBox.Image = System.Drawing.Image.FromStream(fs).GetThumbnailImage(128, 128, Nothing, Nothing)
fs.Close()
If Left > pnlImagesFromDisk.Width - 138 Then
Left = 12
Top = Top + 134
End If
With picBox
.Size = New Size(128, 128)
.SizeMode = PictureBoxSizeMode.Zoom
.Top = Top
.Left = Left
.Visible = True
.Tag = imgInfo.Name
End With
ttLoadedImages.SetToolTip(picBox, "Single Click to View" & vbCrLf & "Double Click to add to selection")
pnlImagesFromDisk.Controls.Add(picBox)
pgbImagesLoaded.Value += 1
lblFilesProcessed.Text = pgbImagesLoaded.Value & "/" & pgbImagesLoaded.Maximum
Application.DoEvents()
AddHandler picBox.Click, New System.EventHandler(AddressOf PreviewImage)
AddHandler picBox.DoubleClick, New System.EventHandler(AddressOf AddToSelection)
AddHandler picBox.MouseEnter, New System.EventHandler(AddressOf pnlImages_MouseEnter)
AddHandler picBox.MouseLeave, New System.EventHandler(AddressOf pnlImages_MouseLeave)
Left = Left + 135
End If
Next
Catch ex As Exception
MsgBox(ex.Message)
End Try
Me.Cursor = Cursors.Arrow
End Sub
In the code block you will notice that the properties of the control to be added is set first before the control gets added.
Alternatively, you can create a UserControl, set the properties as needed and then add it as and when you need it. Creating UserControls gives you more control over how the controls are used, their properties and their events. It is also much easier to make changes to the layout, properties and events should it be required.