我有两行两列。我希望两个单元格的最后一列合并成一个。由于要求,我不使用其他设计选项意味着两个tablelayouts其中第一个表格布局有两行。我在C#中使用Winforms。如何合并表格布局中的两个单元格
| | |
| | |
| | |
|_______________________| |
| | |
| | |
| | |
我有两行两列。我希望两个单元格的最后一列合并成一个。由于要求,我不使用其他设计选项意味着两个tablelayouts其中第一个表格布局有两行。我在C#中使用Winforms。如何合并表格布局中的两个单元格
| | |
| | |
| | |
|_______________________| |
| | |
| | |
| | |
http://msdn.microsoft.com/en-us/library/system.windows.forms.tablelayoutpanel.aspx
例如可以设置在TableLayoutPanel控件行跨度poperty。
您可以在这里查看合并单元格的标题。
在将在表中开始合并的单元格中设置控件的RowSpan属性。即3的RowSpan将具有控制填充其单元格和下面的2个单元格。
ColumnSpan合并到右侧。
在代码中,调用SetRowSpan和/或SetColumnSpan方法。
这里是如何做到这一点的代码
//create a label control, add it to the tableLayoutPanel, and merge it into 3 cells.
Label lbl = new Label();
lbl.Location = new Point(0, 0);
lbl.Text = "This is a test label";
MyTableLayoutPanel.Controls.Add(lbl, 0,0); //start it in cell 0,0
MyTableLayoutPanel.SetColumnSpan(lbl, 3); //merge 3 columns
而不是设置ColumnSpan/RowSpan财产的,可以另一种TableLayoutPanel细胞内添加TableLayoutPanel。不是合并两个单元格,而是分割两个单元格。在你提供的例子中,你会将左列分成两行,而不是将右列合并成一行。
如果您打算将CellBorderStyle属性设置为“None”以外的其他属性,此方法才有优势。我发现这个答案here,其中CSharpFreak也建议另一种方法,我没有尝试。
您可以设置这样的“合并”属性来控制:
比方说,控制是一个Label
和要合并行,那么你就可以做到这一点如下:
TableLayoutPanel table = new TableLayoutPanel();
Label lbl = new Label();
lbl.Text = "test";
lbl.Dock = DockStyle.Fill;
table.Controls.Add(lbl, 0, 0); //initial position
table.SetRowSpan(lbl,2);
的下面的代码应该让你跨越行的所需数量跨越控制/列
TableLayoutPanel tableLayoutPanel1 = new TableLayoutPanel(); // not required if you already have the control added else where or in designer.
TextBox textBox1 = new TextBox(); // not required if you already have the control added else where or in designer.
tableLayoutPanel1.Controls.Add(textBox1);// not required if you already have the control added else where or in designer.
tableLayoutPanel1.SetColumnSpan(textBox1, 2);
tableLayoutPanel1.SetRowSpan(textBox1, 2);
您正在使用哪个表(类)? – 2012-02-22 07:28:59
您使用了c#标签。与c#有关吗?我无法理解。你想要做什么? – sinanakyazici 2012-02-22 07:30:20
我想设计在Winforms中使用TableLayout的用户界面 – 2012-02-22 07:32:18