如何在表格布局中合并两个单元格
我有两行和两列。我希望两个单元格的最后一列合并为一个。由于要求,我不使用其他设计选项,这意味着两个表格布局,其中第一个表格布局有两行。我在 C# 中使用 Winforms。
| | |
| | |
| | |
|_______________________| |
| | |
| | |
| | |
I have two rows and two columns. I want last column of both cells merge into one. Due to requirement I do not use other design options means two tablelayouts in which first table layout has two rows.I am use Winforms in C#.
| | |
| | |
| | |
|_______________________| |
| | |
| | |
| | |
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
请参阅图片进行说明:
See picture for illustration:
以下是如何在代码中执行此操作
Here's how to do it in code
http://msdn.microsoft.com/en-us /library/system.windows.forms.tablelayoutpanel.aspx
例如,您可以在 TableLayoutPanel 控件中设置 RowSpan 属性。
http://msdn.microsoft.com/en-us/library/system.windows.forms.tablelayoutpanel.aspx
For example You can set RowSpan poperty in TableLayoutPanel control.
而不是设置 ColumnSpan/< a href="http://msdn.microsoft.com/en-us/library/system.windows.forms.tablelayoutpanel.setrowspan.aspx" rel="nofollow">RowSpan 属性,您可以添加 TableLayoutPanel 在另一个 TableLayoutPanel。您不是合并两个单元格,而是拆分两个单元格。在您问题中提供的示例中,您将把左列拆分为两行,而不是将右列合并为一行。
仅当您计划设置 时,此方法才有用CellBorderStyle 属性设置为除“无"。我找到了这个答案 此处,其中CSharpFreak 还建议了另一种方法,我没有尝试。
Instead of setting the ColumnSpan/RowSpan property, you can add a TableLayoutPanel within the cell of another TableLayoutPanel. Instead of merging two cells, you are then splitting two cells. In the example you provide in your question, you would be splitting the left column into two rows, instead of merging the right column into one row.
This method is only advantageous if you plan to set the CellBorderStyle property to something other than "None". I found this answer here, where CSharpFreak also suggests another method, which I didn't try.
在将在表中开始合并的单元格中设置控件的 RowSpan 属性。即 RowSpan 为 3 将使控件填充其单元格和下面的 2 个单元格。
ColumnSpan 向右合并。
在代码中,调用 SetRowSpan 和/或 SetColumnSpan 方法。
Set the RowSpan property of the control in the cell that will start the merge in the table. i.e. RowSpan of 3 will have the control fill its cell and the 2 cells below.
ColumnSpan to merge to right.
In code, call the SetRowSpan and/or SetColumnSpan method.
您可以为控件设置这样的“合并”属性:
假设控件是一个标签,并且您想要合并行,那么您可以按如下方式执行操作:
You can set such "merging" property to the Control:
Let's say the Control is a
Label
and you want to merge rows, then you can do it as following:以下代码应允许您将控件跨越所需的行/列数
The following code should allow you to span a control across desired number of rows/columns