0
這是我目前必須動態創建TableLayoutPanel的代碼。動態創建並添加項目到TableLayoutPanel
TableLayoutPanel searchResults_tableLP = new TableLayoutPanel();
searchResults_tableLP.ColumnCount = 2;
searchResults_tableLP.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
searchResults_tableLP.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
searchResults_tableLP.Location = new System.Drawing.Point(3, 3);
searchResults_tableLP.Name = "tableLayoutPanel" + i;
searchResults_tableLP.RowCount = 1;
searchResults_tableLP.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F));
searchResults_tableLP.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F));
searchResults_tableLP.Size = new System.Drawing.Size(200, 100);
searchResults_tableLP.TabIndex = 0;
但是,我怎麼把它變成這個。我不知道我也不能找到語法添加ColumnStyles
和RowStyles
TableLayoutPanel searchResults_tableLP = new TableLayoutPanel
{
ColumnCount = 2,
Location = new System.Drawing.Point(3, 3),
Name = "searchResults_tableLP" + i,
RowCount = 1,
Size = new System.Drawing.Size(612, 59),
TabIndex = 0,
};
,我如何動態地添加內容或控制表? 示例我想向第一列或第二列添加文本?我將如何去做這件事。這似乎是一個簡單的答案,但我無法在任何地方找到它。
只要在設計師中做到這一點。然後查看InitializeComponent()方法,它會顯示出您需要編寫的代碼。或複製/粘貼。 – 2015-04-04 15:45:24
@HansPassant我試過了,但它沒有顯示如何添加列和行的語法。而我不知道如何添加文字 – 2015-04-04 15:47:26
呃,它當然會。點擊「尺寸類型」單選按鈕。 – 2015-04-04 16:18:40