2015-07-20 45 views
0

我在一個面板上有動態標籤和文本框。 我可以刪除面板。沒有問題,但後來我也不知道如何刪除文本框等面板或Winform上清除標籤或文本框

enter image description here

,我希望我可以刷新或清除該面板讓所有的標籤和文本框將被刪除..

 Label makeLabelC = new Label(); 
     makeLabelC.Width = 100; 
     makeLabelC.Font = new Font(makeLabelC.Font.Name, 8, FontStyle.Bold | FontStyle.Underline); 
     makeLabelC.Location = new Point(400, 100); 
     makeLabelC.Name = e.Node.Text; 
     makeLabelC.Text = e.Node.Text; 
     this.Controls.Add(makeLabelC); 
     this.Controls.Add(panel1); 

     TextBox textboxC = new TextBox(); 
     textboxC.Width = 100; 

     textboxC.Location = new Point(500, 100); 
     textboxC.Name = e.Node.Text + "lbl"; 
     textboxC.Text = "enter here"; 
     this.Controls.Add(textboxC); 
     this.Controls.Add(panel1); 


     for (int z = 0; z < n; z++) 
     { 
      Label makeLabel = new Label(); 
      makeLabel.Width = 100; 
      makeLabel.Location = new Point(400, 150 + 2 * z * makeLabel.Height); 
      makeLabel.Name = e.Node.Text; 
      makeLabel.Text = e.Node.Nodes[z].Text; 
      this.Controls.Add(makeLabel); 
      this.Controls.Add(panel1); 

      TextBox textbox = new TextBox(); 
      textbox.Width = 100; 
      textbox.Location = new Point(500, 150 + 2 * z * textbox.Height); 
      textbox.Name = e.Node.Text + "lbl"; 
      textbox.Text = "enter here"; 
      this.Controls.Add(textbox); 
      this.Controls.Add(panel1); 


     } 

    } 

有沒有一種方式與面板如何做到這一點或其他解決方案? 我認爲,該小組可以幫助我有...

感謝雅尼克

+0

如果您移除了一個面板,那麼它的子控件也會被移除,您確定控件在面板上嗎? – Sayse

+0

是的,我添加'this.Controls.Add(文本框)'。以及如何刪除面板並使用相同的屬性和和創建它? –

+1

'這聽起來很喜歡它的形式。請在添加面板和控件的地方添加代碼(針對您的問題) – Sayse

回答

0

您添加控件到窗體,而不是面板 - 你也多次添加

this.Controls.Add(panel1); // do this once 
panel1.Controls.Add(textbox); // add the controls to the panel 

一旦您已經完成了這項工作,當您移除面板時,您還將刪除其子控件。

+1

是的,它!我只是在你自己的評論:)我自己做到了))謝謝 –