我有兩行兩列。我希望兩個單元格的最後一列合併成一個。由於要求,我不使用其他設計選項意味着兩個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