0
我想動態添加TableLayoutPanel。另外,我想動態設置列的寬度。以下是我爲了獲得所需結果而編寫的代碼。但它不工作的財產。我附上了這段代碼輸出的圖像。請幫助...這僅僅是一個測試代碼,我想學習動態創建控件,positin他們,他們的造型等等ColumnStyle不工作屬性
private void ShowAllRecords() {
TableLayoutPanel[] tab = new TableLayoutPanel[MaxRows];
for (int rNumber = 0; rNumber < 1; rNumber++)
{
tab[rNumber] = new TableLayoutPanel();
tab[rNumber].ColumnStyles.Clear();
tab[rNumber].RowCount = 1;
tab[rNumber].ColumnCount = 2;
tab[rNumber].CellBorderStyle = TableLayoutPanelCellBorderStyle.Inset;
tab[rNumber].Location = new Point(0, (rNumber * 50) + 100);
tab[rNumber].Width = 200;
TableLayoutColumnStyleCollection styles = tab[rNumber].ColumnStyles;
tab[rNumber].ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 10));
panel1.Controls.Add(tab[rNumber]);
tab[rNumber].BringToFront();
}
}
輸出: