如何用VS2010的C#实现动态表格功能
2个回答
2017-11-01
展开全部
private void button1_Click(object sender, EventArgs e)
{
int row = int.Parse(txtRow.Text);
int col = int.Parse(txtCol.Text);
tableLayoutPanel1.RowCount = row;
tableLayoutPanel1.ColumnCount = col;
for (int i = 0; i < row; i++)
{
for (int j = 0; j < col; j++)
{
TextBox txt = new TextBox();
txt.Name = "txt" + i + j;
txt.Text = "1";
this.tableLayoutPanel1.Controls.Add(txt, j, i);
}
}
this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill;
this.tableLayoutPanel1.Location = new System.Drawing.Point(0, 0);
}
tableLayoutPanel,vs自带的table控件。窗体上拖放过去,然后添加2个textbox,用来输入,列数和行数,最后添加一个button,这里给出的是整个的button事件
{
int row = int.Parse(txtRow.Text);
int col = int.Parse(txtCol.Text);
tableLayoutPanel1.RowCount = row;
tableLayoutPanel1.ColumnCount = col;
for (int i = 0; i < row; i++)
{
for (int j = 0; j < col; j++)
{
TextBox txt = new TextBox();
txt.Name = "txt" + i + j;
txt.Text = "1";
this.tableLayoutPanel1.Controls.Add(txt, j, i);
}
}
this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill;
this.tableLayoutPanel1.Location = new System.Drawing.Point(0, 0);
}
tableLayoutPanel,vs自带的table控件。窗体上拖放过去,然后添加2个textbox,用来输入,列数和行数,最后添加一个button,这里给出的是整个的button事件
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询