Επεξεργασία

Κοινή χρήση μέσω


Control.ControlCollection Class

Definition

Represents a collection of Control objects.

public: ref class Control::ControlCollection : ICloneable, System::Collections::IList
public: ref class Control::ControlCollection : System::Windows::Forms::Layout::ArrangedElementCollection, ICloneable, System::Collections::IList
[System.ComponentModel.ListBindable(false)]
public class Control.ControlCollection : 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
[System.ComponentModel.ListBindable(false)]
public class Control.ControlCollection : System.Windows.Forms.Layout.ArrangedElementCollection, ICloneable, System.Collections.IList
[<System.ComponentModel.ListBindable(false)>]
type Control.ControlCollection = class
    interface IList
    interface ICollection
    interface IEnumerable
    interface ICloneable
[<System.ComponentModel.ListBindable(false)>]
[<System.Runtime.InteropServices.ComVisible(false)>]
type Control.ControlCollection = class
    inherit ArrangedElementCollection
    interface IList
    interface ICollection
    interface IEnumerable
    interface ICloneable
[<System.ComponentModel.ListBindable(false)>]
type Control.ControlCollection = class
    inherit ArrangedElementCollection
    interface IList
    interface ICollection
    interface IEnumerable
    interface ICloneable
Public Class Control.ControlCollection
Implements ICloneable, IList
Public Class Control.ControlCollection
Inherits ArrangedElementCollection
Implements ICloneable, IList
Inheritance
Control.ControlCollection
Inheritance
Control.ControlCollection
Derived
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)

Initializes a new instance of the Control.ControlCollection class.

Properties

Count

Gets the number of elements contained in the collection.

Count

Gets the number of elements in the collection.

(Inherited from ArrangedElementCollection)
IsReadOnly

Gets a value that indicates whether this collection object is read-only.

IsReadOnly

Gets a value indicating whether the collection is read-only.

(Inherited from ArrangedElementCollection)
Item[Int32]

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

Item[String]

Indicates a Control with the specified key in the collection.

Owner

Gets the control that owns this Control.ControlCollection.

Methods

Add(Control)

Adds the specified control to the control collection.

AddRange(Control[])

Adds an array of control objects to the collection.

Clear()

Removes all controls from the collection.

Contains(Control)

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

ContainsKey(String)

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

CopyTo(Array, Int32)

Copies the elements of the collection to an array, starting at a particular array index.

CopyTo(Array, Int32)

Copies the entire contents of this collection to a compatible one-dimensional Array, starting at the specified index of the target array.

(Inherited from ArrangedElementCollection)
Equals(Object)

Specifies whether the current collection object and the specified object are equal.

Equals(Object)

Determines whether two ArrangedElementCollection instances are equal.

(Inherited from ArrangedElementCollection)
Find(String, Boolean)

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

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.

GetChildIndex(Control)

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

GetEnumerator()

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

GetHashCode()

Returns the hash code for this instance.

GetHashCode()

Returns the hash code for this instance.

(Inherited from ArrangedElementCollection)
GetType()

Gets the Type of the current instance.

(Inherited from Object)
IndexOf(Control)

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

IndexOfKey(String)

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

MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
Remove(Control)

Removes the specified control from the control collection.

RemoveAt(Int32)

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

RemoveByKey(String)

Removes the child control with the specified key.

SetChildIndex(Control, Int32)

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

ToString()

Returns a string that represents the current object.

(Inherited from Object)

Explicit Interface Implementations

ICloneable.Clone()

This API supports the product infrastructure and is not intended to be used directly from your code.

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

ICollection.IsSynchronized

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

(Inherited from ArrangedElementCollection)
ICollection.SyncRoot

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

(Inherited from ArrangedElementCollection)
IList.Add(Object)

This API supports the product infrastructure and is not intended to be used directly from your code.

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

IList.Clear()

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

(Inherited from ArrangedElementCollection)
IList.Contains(Object)

This API supports the product infrastructure and is not intended to be used directly from your code.

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

IList.Contains(Object)

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

(Inherited from ArrangedElementCollection)
IList.IndexOf(Object)

This API supports the product infrastructure and is not intended to be used directly from your code.

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

IList.IndexOf(Object)

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

(Inherited from ArrangedElementCollection)
IList.Insert(Int32, Object)

This API supports the product infrastructure and is not intended to be used directly from your code.

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

IList.Insert(Int32, Object)

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

(Inherited from ArrangedElementCollection)
IList.IsFixedSize

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

(Inherited from ArrangedElementCollection)
IList.Item[Int32]

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

(Inherited from ArrangedElementCollection)
IList.Remove(Object)

This API supports the product infrastructure and is not intended to be used directly from your code.

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

IList.RemoveAt(Int32)

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

(Inherited from ArrangedElementCollection)

Extension Methods

Cast<TResult>(IEnumerable)

Casts the elements of an IEnumerable to the specified type.

OfType<TResult>(IEnumerable)

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

AsParallel(IEnumerable)

Enables parallelization of a query.

AsQueryable(IEnumerable)

Converts an IEnumerable to an IQueryable.

Applies to

See also