Export (0) Print
Expand All

AttributeCollection.Contains Method

Determines whether this collection of attributes has the specified attribute or array of attributes.

Overload List

Determines whether this collection of attributes has the specified attribute.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Function Contains(Attribute) As Boolean
[C#] public bool Contains(Attribute);
[C++] public: bool Contains(Attribute*);
[JScript] public function Contains(Attribute) : Boolean;

Determines whether this attribute collection contains all the specified attributes in the attribute array.

[Visual Basic] Overloads Public Function Contains(Attribute()) As Boolean
[C#] public bool Contains(Attribute[]);
[C++] public: bool Contains(Attribute*[]);
[JScript] public function Contains(Attribute[]) : Boolean;

Example

The following example compares the attributes in button1 and textBox1 to see whether the attributes for the button are contained in the attributes for the text box. It assumes that both button1 and textBox1 have been created on a form.

[Visual Basic] 
Private Sub ContainsAttributes()
    ' Creates a new collection and assigns it the attributes for button1.
    Dim myCollection As AttributeCollection
    myCollection = TypeDescriptor.GetAttributes(button1)
      
    ' Checks to see whether the attributes in myCollection are the attributes for textBox1.
    Dim myAttrArray(100) As Attribute
    TypeDescriptor.GetAttributes(textBox1).CopyTo(myAttrArray, 0)
    If myCollection.Contains(myAttrArray) Then
        textBox1.Text = "Both the button and text box have the same attributes."
    Else
        textBox1.Text = "The button and the text box do not have the same attributes."
    End If
End Sub

[C#] 
private void ContainsAttributes() {
   // Creates a new collection and assigns it the attributes for button1.
   AttributeCollection myCollection;
   myCollection = TypeDescriptor.GetAttributes(button1);    

   // Checks to see whether the attributes in myCollection are the attributes for textBox1.
   Attribute[] myAttrArray = new Attribute[100];
   TypeDescriptor.GetAttributes(textBox1).CopyTo(myAttrArray, 0);
   if (myCollection.Contains(myAttrArray))
      textBox1.Text = "Both the button and text box have the same attributes.";
   else
      textBox1.Text = "The button and the text box do not have the same attributes.";
}

[C++] 
private:

    void ContainsAttributes() 
    {
        // Creates a new collection and assigns it the attributes for button1.
        AttributeCollection* myCollection;
        myCollection = TypeDescriptor::GetAttributes( button1 );    

        
        // Checks to see whether the attributes in myCollection are the attributes for textBox1.
        Attribute*    myAttrArray[] = new Attribute*[100];

        TypeDescriptor::GetAttributes( textBox1 )->CopyTo(myAttrArray, 0);
        if (myCollection->Contains(myAttrArray))
            textBox1->Text = S"Both the button and text box have the same attributes.";
        else
            textBox1->Text = S"The button and the text box do not have the same attributes.";
    }

[JScript] 
private function ContainsAttributes() {
   // Creates a new collection and assigns it the attributes for button1.
   var myCollection : AttributeCollection;
   myCollection = TypeDescriptor.GetAttributes(button1);    

   // Checks to see whether the attributes in myCollection are the attributes for textBox1.
   var myAttrArray : Attribute[]  = new Attribute[100];
   TypeDescriptor.GetAttributes(textBox1).CopyTo(myAttrArray, 0);
   if (myCollection.Contains(myAttrArray))
      textBox1.Text = "Both the button and text box have the same attributes.";
   else
      textBox1.Text = "The button and the text box do not have the same attributes.";

}

See Also

AttributeCollection Class | AttributeCollection Members | System.ComponentModel Namespace

Show:
© 2014 Microsoft