I am using Visual Studio 2022 and my language of choice is VB. When the program starts it creates Multiple Panels that are located in the same position created from data from a database.
No matter what I do, I can not get any of the panels to show. I can search for the panels and verify the panels exist, I can search the panels and verify that there are buttons in the panels. However I can not get each individual panel to show.
I am going to list all the panels that are created in the order they are created and they are all in the exact same position and size.
- panel2
- pnlDeptItems01
- pnlDeptItems11
- pnlDeptItems22
- pnlDeptItems23
- pnlDeptItems24
- pnlDeptItems25
- pnlDeptItems26
- pnlDeptItems27
- pnlDeptItems28
- pnlDeptItems29
- pnlDeptItems32
- pnlDeptItems54
- pnlDeptItems82
- pnlDeptItems83
- pnlDeptItems84
- pnlDeptItems85
- pnlDeptItems96
- pnlDeptItems97
- pnlDeptItems98
- pnlDeptItems99
Visible and Enabled are set to true for all panels on creation.
Below is the code that I use to search for the panel by name and if I find it then try to make it visible which it already is and then I try to bring it to front. And it does absolutely nothing but keeps the 1st panel visible.
For Each control In Me.Controls.OfType(Of Panel)
If control.Name = btnPanelName Then
control.Controls.Add(oButton)
control.Visible = True
control.BringToFront()
Console.WriteLine(control.Name & " " & oButton.Name)
End If
Next
CODE TO CREATE PANELS
Private Sub CreateNewPanel(ByRef pnlName As String, ByRef pnltopx As Integer, ByRef pnlLefty As Integer, ByRef pnlSizex As Integer, ByRef pnlSizey As Integer)
Dim iPanel As Panel
iPanel = New Panel
iPanel.Name = pnlName
iPanel.Enabled = True
iPanel.Visible = False
iPanel.Top = pnltopx
iPanel.Left = pnlLefty
iPanel.Size = New Size(pnlSizex, pnlSizey)
iPanel.AutoScroll = True
Me.Controls.Add(iPanel)
If iPanel.Name = "pnlDepartments" Or iPanel.Name = "pnlDeptItems26" Then
iPanel.Visible = True
iPanel.BringToFront()
End If
End Sub
I then tried doing this and this does not work either:
For Each control In Me.Controls.OfType(Of Panel)
If control.Name = btnPanelName Then
control.Controls.Add(oButton)
End If
If control.Name = "pnlDeptItems26" Then
control.Visible = True
End If
Next
Code that is called to create the panels
CreateNewPanel("pnlDeptItems" & dataDeptId, 608, 5, 429, 479)
dataDeptId is pulled from a database in a loop.
Can someone explain to me why this is not working or what the work around is? I know it has something to do with all the panels that are created being created in the exact same position.
Thanks, Shawn Mulligan
CodePudding user response:
I found the solution. After reading my post I took notice that for some reason that my paneltopx and my panellefty were reversed and too large for some reason as well as my panelsizey and panelsizex.
I made the adjustments and made sure that all panels visibility was set to false, and now when I set visibility to true, the correct panel displays with the buttons that I created.
Thanks, Shawn Mulligan