0
我創建了一個帶有100個插槽(10x10)的TableLayoutPanel
。在每個單元中,我創建了一個新的TableLayoutPanel
。 然後創建陣列TableLayoutPanel[,] tb = new TableLayoutPanel[10,10];
將TableLayoutPanel中的每個控件分配給2D數組
所以現在我想通過主(10×10)的每個小區環TableLayoutPanel中,並分配在每個小區中的每個tablelayoutpanel
到2D陣列中的存儲器插槽。
我一直在頭腦風暴和網上搜索和種得到的暗示,這將涉及兩個for
循環和一個foreach
循環,但我很困惑,什麼去哪裏。
從我所編碼的,我覺得做任務的最佳地方是這個代碼塊中:
for (int i = 0; i < 10; i++)
{
for (int j = 0; j < 10; j++)
{
mainTPL.Controls.Add(new TableLayoutPanel
{
Name = "tbl" + i + "-" + j,
CellBorderStyle = TableLayoutPanelCellBorderStyle.Inset,
Size = new Size(70, 70),
RowCount = 2,
ColumnCount = 3,
}, i, j);
//Could I do the assignment right here?
}
}
我沒有for each循環,但是是可以做到的在雙循環中的賦值?我如何指定新創建的TableLayoutPanel
將其分配給數組? 謝謝你們。