tableLayoutPanel: 表格版面配置面板,適合以表格形式規則的動態添加(顯示)控制項。使用方法概述:將 tableLayoutPanel 拖放到表單指定地區 ——一般做些基本的設定 或添加行或列,其它的就需寫代碼來控制顯示 /// <summary>
/// 繪製控制項
/// </summary>
private void Paintcontrol()
{
// 刪除預設的行和列樣式
tableLayoutPanel1.ColumnStyles.Clear();
tableLayoutPanel1.RowStyles.Clear();
this.tableLayoutPanel1.Controls.Clear();
this.tableLayoutPanel1.ColumnCount = 4;
Label lb = null;
if (tableitems != null && tableitems.Rows.Count > 0)
{
this.tableLayoutPanel1.RowCount = (tableitems.Rows.Count % 2 == 0 ? tableitems.Rows.Count /2 : tableitems.Rows.Count /2 + 1);
this.tableLayoutPanel1.Height = 30 * this.tableLayoutPanel1.RowCount;
this.Height = this.tableLayoutPanel1.Height;
for (int RowIndex = 0; RowIndex < tableitems.Rows.Count; RowIndex++)
{
lb = new Label();
lb.Text = tableitems.Rows[RowIndex]["ItemText"].ToString();
lb.Parent = tableLayoutPanel1;
this.tableLayoutPanel1.Controls.Add(lb, RowIndex%2*2, RowIndex/2);
TextBox text = new TextBox();
text.Name = "txt" + tableitems.Rows[RowIndex]["ItemValue"].ToString();
text.Width = 148;
text.Parent = tableLayoutPanel1;
this.tableLayoutPanel1.Controls.Add(text, RowIndex%2*2+1, RowIndex/2);
}
}
}