Home > Net >  How do you show a panel in VB dot net, if all the panels are created dynamically and sit in the exac
How do you show a panel in VB dot net, if all the panels are created dynamically and sit in the exac

Time:01-08

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.

  1. panel2
  2. pnlDeptItems01
  3. pnlDeptItems11
  4. pnlDeptItems22
  5. pnlDeptItems23
  6. pnlDeptItems24
  7. pnlDeptItems25
  8. pnlDeptItems26
  9. pnlDeptItems27
  10. pnlDeptItems28
  11. pnlDeptItems29
  12. pnlDeptItems32
  13. pnlDeptItems54
  14. pnlDeptItems82
  15. pnlDeptItems83
  16. pnlDeptItems84
  17. pnlDeptItems85
  18. pnlDeptItems96
  19. pnlDeptItems97
  20. pnlDeptItems98
  21. 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

  • Related