0

I have created a flowlayoutpanel that renders panels inside on it for navigation pruposes. Now, I am doing the add of elements programmatically do reduce slow of VB 2012 application on editing codes. But then, I have an unexpected result on adding a new panel on my flowlayoutpanel.

enter image description here

Here is my code on creating the new panel:

    Dim AppPanel As New Panel
    Dim AppTableLayoutPanel As New TableLayoutPanel
    Dim RecordCountPanel As New Panel
    Dim RecordCountLabel As New Label
    Dim RecordNameLabel As New Label
    Dim AddButton As New Button

    AppPanel.Width = 259
    AppPanel.Height = 43
    AppPanel.Margin = New Padding(0, 0, 0, 5)
    AppPanel.BackColor = SystemColors.InactiveBorder

    RecordCountPanel.BackColor = Color.SteelBlue
    RecordCountPanel.Margin = New Padding(0)
    RecordCountPanel.Dock = DockStyle.Fill

    RecordCountLabel.Anchor = System.Windows.Forms.AnchorStyles.Left
    RecordCountLabel.Text = "245" '
    RecordCountLabel.Width = 70
    RecordCountLabel.Height = 42
    RecordCountLabel.Padding = New Padding(0, 6, 0, 0)
    RecordCountLabel.TextAlign = ContentAlignment.MiddleCenter
    RecordCountLabel.Font = New Font("Microsoft Sans Serif", 12)
    RecordCountLabel.ForeColor = Color.White
    'RecordCountLabel.BackColor = Color.Orange

    RecordCountLabel.Location.X.Equals(4)
    RecordCountLabel.Location.Y.Equals(12)

    AppTableLayoutPanel.Dock = DockStyle.Fill
    AppTableLayoutPanel.ColumnCount = 3
    AppTableLayoutPanel.ColumnStyles.Add(New ColumnStyle(SizeType.Percent, 33.18F))
    AppTableLayoutPanel.Controls.Add(RecordCountPanel, 0, 0)

    AddButton.Dock = DockStyle.Fill
    AddButton.Font = New Font("Microsoft Sans Serif", 14)
    AddButton.Text = "+"

    RecordNameLabel.Anchor = System.Windows.Forms.AnchorStyles.Left
    RecordNameLabel.Text = "Request Item Logs"
    RecordNameLabel.Width = 150
    RecordNameLabel.Height = 42
    RecordNameLabel.Padding = New Padding(0, 6, 0, 0)
    RecordNameLabel.TextAlign = ContentAlignment.MiddleLeft
    RecordNameLabel.Font = New Font("Microsoft Sans Serif", 10)

    AppTableLayoutPanel.ColumnStyles.Add(New ColumnStyle(SizeType.Percent, 66.82F))
    AppTableLayoutPanel.Controls.Add(RecordNameLabel, 1, 0)

    AppTableLayoutPanel.ColumnStyles.Add(New ColumnStyle(SizeType.Absolute, 53.0F))
    AppTableLayoutPanel.Controls.Add(AddButton, 2, 0)

    RecordCountPanel.Controls.Add(RecordCountLabel)

    AppPanel.Controls.Add(AppTableLayoutPanel)

    Main.FlowlayoutPanel.Controls.Add(AppPanel)
  • The text on the 2nd column is not showing
  • The button on the 3rd column shows unusual

In Addition: If I remove AppTableLayoutPanel.Controls.Add(RecordCountPanel, 0, 0), the other elements will be rendered normally.

enter image description here

grldtcsn
  • 47
  • 1
  • 1
  • 12
  • If each group of controls is the same then you should not be creating a `Panel` and then other controls too. Design your own user control that contains all the child controls and their behaviour up front and then all you have to do is create an instance of that user control and add it to your `FlowLayoutPanel`. – jmcilhinney Jun 02 '14 at 04:32
  • @jmcilhinney This code is the instance itself. This will be reused as what you have said. My problem is that, I don't figure out the issue I listed here. Thank you for concerning on my issue. (: – grldtcsn Jun 02 '14 at 05:09
  • There should be no `Panel`. You should create a user control. In short, you're trying to do it the wrong way. – jmcilhinney Jun 02 '14 at 05:44

0 Answers0