Control.Controls 属性参考

Control.Controls 属性[C#]
获取包含在控件内的控件的集合。

[Visual Basic]
Public ReadOnly Property Controls As Control.ControlCollection

[C#]
public Control.ControlCollection Controls {get;}

[C++]
public: __property Control.ControlCollection* get_Controls();

[JScript]
public function get Controls() : Control.ControlCollection;

属性值
一个 Control.ControlCollection,它表示控件内包含的控件的集合。

备注
Control 可以充当控件集合的父级。例如,当将多个控件添加到 Form 时,每一个控件都是 Control.ControlCollection
对象的成员,该对象被分配给窗体的 Controls 属性,窗体从 Control 类派生而来。 可以使用 Control.ControlCollection 类的方法,在分配给 Controls 属性的 Control.ControlCollection
对象中操作控件。 将多个控件添加到父控件时,建议在初始化要添加的控件之前调用 SuspendLayout 方法。将控件添加到父控件之后,
调用 ResumeLayout 方法。这样就可以提高带有许多控件的应用程序的性能。 示例 [Visual Basic, C#, C++] 下面的示例从派生类 Panel 的 Control.ControlCollection 中移除一个
Control(如果它是该集合的成员)。该示例假定您已在 Form 上创建了一个 Panel、一个 Button 以及至少一个
RadioButton 控件。将 RadioButton 控件添加到 Panel 控件,而将 Panel 控件添加到 Form。单击该按钮
时,从 Control.ControlCollection 中移除名为 radioButton2 的单选按钮。 [Visual Basic] ' Remove the RadioButton control if it exists. Private Sub RemoveButton_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles RemoveButton.Click If Panel1.Controls.Contains(RadioAddRangeButton) Then Panel1.Controls.Remove(RadioAddRangeButton) End If End Sub [C#] // 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); } } [C++] // 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); } }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值