在Panel或Winform上清除标签或文本框(Clear Labels or Textbox on Panel or Winform)

编程入门 行业动态 更新时间:2024-10-14 12:21:26
在Panel或Winform上清除标签或文本框(Clear Labels or Textbox on Panel or Winform)

我在一个面板上有动态标签和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 panel

Once you have done this, when you remove the panel, you will also remove its child controls.

更多推荐

本文发布于:2023-08-06 17:15:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1454485.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文本框   标签   Winform   Panel   Labels

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!