winform 如何设置TableLayoutPanel 的各行高度均等 5
2016-01-08 · 做真实的自己 用良心做教育
千锋教育
千锋教育专注HTML5大前端、JavaEE、Python、人工智能、UI&UE、云计算、全栈软件测试、大数据、物联网+嵌入式、Unity游戏开发、网络安全、互联网营销、Go语言等培训教育。
向TA提问
关注
展开全部
代码及说明如下:
private void InitLayoutDemo()
{
TableLayoutPanel demoLayoutPanel = new TableLayoutPanel();
demoLayoutPanel.Dock = DockStyle.Fill;
this.Controls.Add(demoLayoutPanel);
int row = 3, col = 3;
DynamicLayout(demoLayoutPanel, row, col);
for (int i = 0; i < row; i++)
{
for (int j = 0; j < col; j++)
{
Button btn = new Button();
btn.Text = string.Format("({0},{1})", i, j);
btn.Dock = DockStyle.Fill;
demoLayoutPanel.Controls.Add(btn);
demoLayoutPanel.SetRow(btn, i);
demoLayoutPanel.SetColumn(btn, j);
}
}
}
/// <summary>
/// 动态布局
/// </summary>
/// <param name="layoutPanel">布局面板</param>
/// <param name="row">行</param>
/// <param name="col">列</param>
private void DynamicLayout(TableLayoutPanel layoutPanel, int row, int col)
{
layoutPanel.RowCount = row; //设置分成几行
for (int i = 0; i < row; i++)
{
layoutPanel.RowStyles.Add(new RowStyle(SizeType.Percent, 100F));
}
layoutPanel.ColumnCount = col; //设置分成几列
for (int i = 0; i < col; i++)
{
layoutPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100F));
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询