MSDN稳当下面的示例从派生类 Panel 的 Control.ControlCollection 中移除一个 Control(如果它是该集合的成员)。该示例假定您已在 Form 上创建了一个 Panel、一个 Button 以及至少一个 RadioButton 控件。将 RadioButton 控件添加到 Panel 控件,而将 Panel 控件添加到 Form。单击该按钮时,从 Control.ControlCollection 中移除名为 radioButton2 的单选按钮。// Remove the RadioButton control if it exists.
private void removeButton_Click(object sender, System.EventArgs e)
{
if(panel1.Controls.Contains(removeButton))
{
panel1.Controls.Remove(removeButton);
}
}
private void removeButton_Click(object sender, System.EventArgs e)
{
if(panel1.Controls.Contains(removeButton))
{
panel1.Controls.Remove(removeButton);
}
}
System.Windows.Forms.IContainerControl
接口
{
MessageBox.Show("有东西在里面");
}
if(groupbox1.Container.Components.Count>0)
{
MessageBox.Show("有东西在里面");
}