Control.ControlCollection Control.ControlCollection Control.ControlCollection Control.ControlCollection Class

Definition

Represents a collection of Control objects.

public: ref class Control::ControlCollection : System::Windows::Forms::Layout::ArrangedElementCollection, ICloneable, System::Collections::IList
[System.ComponentModel.ListBindable(false)]
[System.Runtime.InteropServices.ComVisible(false)]
public class Control.ControlCollection : System.Windows.Forms.Layout.ArrangedElementCollection, ICloneable, System.Collections.IList
type Control.ControlCollection = class
    inherit ArrangedElementCollection
    interface IList
    interface ICollection
    interface IEnumerable
    interface ICloneable
Public Class Control.ControlCollection
Inherits ArrangedElementCollection
Implements ICloneable, IList
Inheritance
Control.ControlCollectionControl.ControlCollectionControl.ControlCollectionControl.ControlCollection
Attributes
Implements

Examples

The following code example removes a Control from the Control.ControlCollection of the derived class Panel if it is a member of the collection. The example requires that you have created a Panel, a Button, and at least one RadioButton control on a Form. The RadioButton controls are added to the Panel control, and the Panel control added to the Form. When the button is clicked, the radio button named radioButton2 is removed from the Control.ControlCollection.

   // 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 );
      }
   }
// 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);
   }
}
  ' 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(RemoveButton) Then
          Panel1.Controls.Remove(RemoveButton)
      End If
  End Sub

Remarks

The Add, Remove, and RemoveAt methods enable you to add and remove individual controls from the collection. You can also use the AddRange or Clear methods to add or remove all the controls from the collection.

You can determine if a Control is a member of the collection by passing the control into the Contains method. To get the index value of the location of a Control in the collection, pass the control into the IndexOf method. The collection can be copied into an array by calling the CopyTo method.

Constructors

Control.ControlCollection(Control) Control.ControlCollection(Control) Control.ControlCollection(Control) Control.ControlCollection(Control)

Initializes a new instance of the Control.ControlCollection class.

Properties

Count Count Count Count
ICollection.IsSynchronized ICollection.IsSynchronized ICollection.IsSynchronized ICollection.IsSynchronized

For a description of this member, see the IsSynchronized property.

(Inherited from ArrangedElementCollection)
ICollection.SyncRoot ICollection.SyncRoot ICollection.SyncRoot ICollection.SyncRoot

For a description of this member, see the SyncRoot property.

(Inherited from ArrangedElementCollection)
IList.IsFixedSize IList.IsFixedSize IList.IsFixedSize IList.IsFixedSize

For a description of this member, see the IsFixedSize property.

(Inherited from ArrangedElementCollection)
IList.Item[Int32] IList.Item[Int32] IList.Item[Int32] IList.Item[Int32]

For a description of this member, see the Item[Int32] property.

(Inherited from ArrangedElementCollection)
IsReadOnly IsReadOnly IsReadOnly IsReadOnly
Item[Int32] Item[Int32] Item[Int32] Item[Int32]

Indicates the Control at the specified indexed location in the collection.

Item[String] Item[String] Item[String] Item[String]

Indicates a Control with the specified key in the collection.

Owner Owner Owner Owner

Gets the control that owns this Control.ControlCollection.

Methods

Add(Control) Add(Control) Add(Control) Add(Control)

Adds the specified control to the control collection.

AddRange(Control[]) AddRange(Control[]) AddRange(Control[]) AddRange(Control[])

Adds an array of control objects to the collection.

Clear() Clear() Clear() Clear()

Removes all controls from the collection.

Contains(Control) Contains(Control) Contains(Control) Contains(Control)

Determines whether the specified control is a member of the collection.

ContainsKey(String) ContainsKey(String) ContainsKey(String) ContainsKey(String)

Determines whether the Control.ControlCollection contains an item with the specified key.

CopyTo(Array, Int32) CopyTo(Array, Int32) CopyTo(Array, Int32) CopyTo(Array, Int32)
Equals(Object) Equals(Object) Equals(Object) Equals(Object)
Find(String, Boolean) Find(String, Boolean) Find(String, Boolean) Find(String, Boolean)

Searches for controls by their Name property and builds an array of all the controls that match.

GetChildIndex(Control) GetChildIndex(Control) GetChildIndex(Control) GetChildIndex(Control)

Retrieves the index of the specified child control within the control collection.

GetChildIndex(Control, Boolean) GetChildIndex(Control, Boolean) GetChildIndex(Control, Boolean) GetChildIndex(Control, Boolean)

Retrieves the index of the specified child control within the control collection, and optionally raises an exception if the specified control is not within the control collection.

GetEnumerator() GetEnumerator() GetEnumerator() GetEnumerator()

Retrieves a reference to an enumerator object that is used to iterate over a Control.ControlCollection.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()
GetType() GetType() GetType() GetType()

Gets the Type of the current instance.

(Inherited from Object)
IndexOf(Control) IndexOf(Control) IndexOf(Control) IndexOf(Control)

Retrieves the index of the specified control in the control collection.

IndexOfKey(String) IndexOfKey(String) IndexOfKey(String) IndexOfKey(String)

Retrieves the index of the first occurrence of the specified item within the collection.

MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
Remove(Control) Remove(Control) Remove(Control) Remove(Control)

Removes the specified control from the control collection.

RemoveAt(Int32) RemoveAt(Int32) RemoveAt(Int32) RemoveAt(Int32)

Removes a control from the control collection at the specified indexed location.

RemoveByKey(String) RemoveByKey(String) RemoveByKey(String) RemoveByKey(String)

Removes the child control with the specified key.

SetChildIndex(Control, Int32) SetChildIndex(Control, Int32) SetChildIndex(Control, Int32) SetChildIndex(Control, Int32)

Sets the index of the specified child control in the collection to the specified index value.

ToString() ToString() ToString() ToString()

Returns a string that represents the current object.

(Inherited from Object)

Explicit Interface Implementations

ICloneable.Clone() ICloneable.Clone() ICloneable.Clone() ICloneable.Clone()

For a description of this member, see Clone().

IList.Add(Object) IList.Add(Object) IList.Add(Object) IList.Add(Object)

For a description of this member, see Add(Object).

IList.Clear() IList.Clear() IList.Clear() IList.Clear()

For a description of this member, see the Clear() method.

(Inherited from ArrangedElementCollection)
IList.Contains(Object) IList.Contains(Object) IList.Contains(Object) IList.Contains(Object)
IList.IndexOf(Object) IList.IndexOf(Object) IList.IndexOf(Object) IList.IndexOf(Object)
IList.Insert(Int32, Object) IList.Insert(Int32, Object) IList.Insert(Int32, Object) IList.Insert(Int32, Object)
IList.Remove(Object) IList.Remove(Object) IList.Remove(Object) IList.Remove(Object)

For a description of this member, see Remove(Object).

IList.RemoveAt(Int32) IList.RemoveAt(Int32) IList.RemoveAt(Int32) IList.RemoveAt(Int32)

For a description of this member, see the RemoveAt(Int32) method.

(Inherited from ArrangedElementCollection)

Extension Methods

Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable)

Casts the elements of an IEnumerable to the specified type.

OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable)

Filters the elements of an IEnumerable based on a specified type.

AsParallel(IEnumerable) AsParallel(IEnumerable) AsParallel(IEnumerable) AsParallel(IEnumerable)

Enables parallelization of a query.

AsQueryable(IEnumerable) AsQueryable(IEnumerable) AsQueryable(IEnumerable) AsQueryable(IEnumerable)

Converts an IEnumerable to an IQueryable.

Applies to

See Also