我在Visual Studio / windows窗体应用程序中有一个面板。但我不能用code.It工作,如果我没有面板工作,但我需要它.MyCodes:
PictureBox[] pipe = new PictureBox[3];
private void Form1_Load(object sender, EventArgs e)
{
CreatePipes(1);}
private void CreatetopPipes(int Number)
{
for (int i = 0; i <= Number; i++)
{
PictureBox temp = new PictureBox();
this.Controls.Add(temp);
temp.Width = 50;
temp.Height = 350;
temp.BorderStyle = BorderStyle.FixedSingle;
temp.BackColor = Color.Red;
temp.Top = 30;
temp.Left = 300;
topPipe[i] = temp;
topPipe[i].Visible = true;
}
}
答案 0 :(得分:0)
您可以使用panelName.Controls.Add(temp)
,我建议您更改PictureBox
中for loop
的顶部以查看所有PictureBox
,如下所示:
private void CreatetopPipes(int Number)
{
for (int i = 0; i <= Number; i++)
{
PictureBox temp = new PictureBox();
panelName.Controls.Add(temp);
temp.Width = 50;
temp.Height = 350;
temp.BorderStyle = BorderStyle.FixedSingle;
temp.BackColor = Color.Red;
temp.Top = temp.Height * panelName.Controls.Count;
temp.Left = 300;
topPipe[i] = temp;
topPipe[i].Visible = true;
}
}