我在一个面板上有动态标签和TextBox。 我可以删除Panel。 没问题,但我也不知道如何删除文本框等
我希望我可以刷新或清除面板,以便删除所有标签和文本框。
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); } }有没有办法让面板如何做到这一点或其他解决方案? 我以为小组可以帮助我......
谢谢Janik
I have dynamic Labels and TextBox's on one panel. I can delete the Panel. No Problem but then I also don't know how to delete the Textboxes etc
and i hoped that i can refresh or clear the panel so that all labels and textboxes will deleted..
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); } }is there a way with panel how to do this or an other solution? I thought that the Panel can help me there...
thanks Janik
最满意答案
您将控件添加到窗体而不是面板 - 您还要多次添加
this.Controls.Add(panel1); // do this once panel1.Controls.Add(textbox); // add the controls to the panel完成此操作后,当您删除面板时,您还将删除其子控件。
You are adding the controls to the form instead of the panel - which you also add multiple times
this.Controls.Add(panel1); // do this once panel1.Controls.Add(textbox); // add the controls to the panelOnce you have done this, when you remove the panel, you will also remove its child controls.
更多推荐
发布评论