我有這樣的循環:c#如何到達程序運行時創建的面板?
int iPanelNumber = 1;
foreach (string[] Persons in alItems)
{
Panel pPanelContainer = new Panel();
pPanelContainer.Width = contentPanel.Width;
pPanelContainer.Height = 50;
pPanelContainer.BackColor = Color.FromArgb(
Convert.ToInt32(aWhiteContentBackgroundColors[0]),
Convert.ToInt32(aWhiteContentBackgroundColors[1]),
Convert.ToInt32(aWhiteContentBackgroundColors[2]));
pPanelContainer.Name = "PanelContainer" + iPanelNumber.ToString();
pPanelContainer.Visible = false;
pPanelContainer.Location = new Point(0, 0);
}
因此,大家可以看到,我已經給了我創作的名爲「PanelContainer1」面板,「PanelContainer2」等等
但如何才能達到我這些面板?
我當然不能用書面形式到達他們:
PanelContainer1.visible = true;
任何人有一個想法?
在此先感謝
順便說一句:你沒有在你的循環中遞增iPanelNumber!這是複製/過去錯誤嗎? – M4N