以编程方式在VB中的flowlayoutpanel上生成具有其元素的面板

时间:2014-06-02 04:25:38

标签: vb.net visual-studio-2012 flowlayoutpanel

我创建了一个flowlayoutpanel,用于渲染面板内部的导航元素。现在,我正在以编程方式添加元素,在编辑代码上减少VB 2012应用程序的速度。但是,我在 flowlayoutpanel 上添加新面板时出现意外结果。

enter image description here

以下是我创建新面板的代码:

    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)
  • 第二栏上的文字未显示
  • 第3列上的按钮显示异常

另外: 如果我删除AppTableLayoutPanel.Controls.Add(RecordCountPanel, 0, 0),其他元素将正常呈现。

enter image description here

0 个答案:

没有答案