我正在使用tablelayoutpanel进行一些动态创建的控件。 但是在调整窗体大小(最大化)时,列不能正确对齐。
中给出这是我的代码
TableLayoutPanel panelItems = new TableLayoutPanel();
panelItems.ColumnStyles.Clear();
panelItems.Padding = new Padding(0,0,0,100);
panelItems.Dock = DockStyle.Bottom;
panelItems.ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize));
panelItems.Tag = item.id;
panelItems.ColumnCount = 3;
panelItems.RowCount = 2;
panelItems.AutoSizeMode = AutoSizeMode.GrowAndShrink;
this.Controls.Add(panelItems);
//Get items
if (categoryItemProducts.Any())
{
foreach (var product in categoryItemProducts)
{
//Create new control
ctrItem productItem = new ctrItem(product.id);
productItem.BackColor = Color.Brown;
//productItem.Anchor = (AnchorStyles.Left | AnchorStyles.Right);
productItem.Anchor = AnchorStyles.None;
//Add it to tablelayout
panelItems.Controls.Add(productItem);
}
}
panelItems.AutoScroll = false;
panelItems.Visible = false;
panelItems.AutoSize = true;
请帮帮我。