页: 1 表格1代码>载荷显示Form2
:
Form frm = new Form2();
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
frm.Show();
}
<代码>Form1 有一个纽芬兰文在<>Form2上动态创建10纽芬兰文。
private void btnCreateButtons_Click(object sender, EventArgs e)
{
for (int t=0;t<10;t++)
{
Button button = new Button();
button.Text = "Button " + t.ToString();
button.Location = new Point(10, (10+(button.Height*t)));
frm.Controls.Add(button);
}
}
在一次点击[Create Buttons]之后,有两种形式。
Then the goal is that when the [Dispose] button is clicked on Form1
, it will properly remove and dispose all of the buttons on Form2
that were created in the first step. But I have a problem about destroying the dynamic objects created.
private void btnDisposeAll_Click(object sender, EventArgs e)
{
foreach(Control control in frm.Controls)
{
if (control != null)
{
this.Controls.Remove(control);
control.Dispose();
}
}
}
当我想要摧毁这一充满活力的县时,处置方法不能正确操作。 在<代码>Form2中,只有一些有活力的吨位消失。
what s wrong in my code? thanks