修改tablelayoutPanel 内控件的名称,文字大小,背景颜色
//枚举TableLayoutPanel 所有子控件。
foreach (Control c in this.tbPI.Controls)
//修改文本
c.Text = "0";
//修改背景颜色
c.BackColor = Color.Blue;
//修改文字字体
c.Font = new Font("宋体", 10);
private void button2_Click(object sender, EventArgs e)
{
//修改第6行第1列数据,下标从0开始
int i = 5;
int j = 0;
Label label = (Label)table.Controls[i * 5 + j];
label.Text = "已修改";
label.ForeColor = Color.Red;
}
tablelayoutPanel 跨行添加
你设计的时候把 几行几列设好 我这个市三行三列
this.tableLayoutPanel1.Controls.Add(this.treeView1, 0, 0);
this.tableLayoutPanel1.Controls.Add(this.pictureBox1, 1, 0);
this.tableLayoutPanel1.Controls.Add(this.panel1, 1, 1);
this.tableLayoutPanel1.Controls.Add(this.panel2, 1, 2);
//跨列
this.tableLayoutPanel1.SetRowSpan(this.treeView1, 3);
tablelayoutPanel 修改标题
// 遍历所有的控件,初始化IO表的字符
int IOnumb=0;
foreach (Control c in this.tbPI.Controls)
{
c.Text = "I-"+IOnumb++.ToString();
}