2016-05-13 5 views
0

私はVisual Studio/windowsフォームapp.Butでパネルを持っていますが、コードなしでpictureBoxを追加することはできません。パネルなしで作業すると機能します.MyCodes:コード付きのパネルにpictureBoxを追加する

 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; 


     } 
    } 
+2

'this' - ' Form'です。代わりにパネルを使用してください。 –

+0

そして、それらをすべて同じ場所に積み重ねないでください! – TaW

答えて

0

あなたはpanelName.Controls.Add(temp)を使用することができますし、私はこのようなすべてのPictureBox、表示するfor loopPictureBoxのトップを変更するように助言する:

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; 

    } 
} 
+0

ありがとう:) –

関連する問題