EditorPartCollection.Contains(EditorPart) Méthode

Définition

Retourne une valeur indiquant si un contrôle particulier existe dans la collection.

public:
 bool Contains(System::Web::UI::WebControls::WebParts::EditorPart ^ editorPart);
public bool Contains (System.Web.UI.WebControls.WebParts.EditorPart editorPart);
member this.Contains : System.Web.UI.WebControls.WebParts.EditorPart -> bool
Public Function Contains (editorPart As EditorPart) As Boolean

Paramètres

editorPart
EditorPart

EditorPart testé pour son état en tant que membre de la collection.

Retours

Valeur Boolean indiquant si EditorPart existe dans la collection.

Exemples

L’exemple de code suivant montre comment déterminer si un contrôle particulier EditorPart se trouve dans un EditorPartCollection objet . Pour obtenir le code complet requis pour exécuter l’exemple, consultez la section Exemple de la vue d’ensemble de la EditorPartCollection classe.

Le code de l’événement Button1_Click n’ajoute pas le LayoutEditorPart1 contrôle à l’objet EditorPartCollection lorsqu’il ajoute les autres contrôles. Pour confirmer que le LayoutEditorPart1 contrôle ne figure pas dans la collection, le code utilise la Contains méthode .

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

  protected void Button1_Click(object sender, EventArgs e)
  {
    ArrayList list = new ArrayList(2);
    list.Add(AppearanceEditorPart1);
    list.Add(PropertyGridEditorPart1);
    // Pass an ICollection object to the constructor.
    EditorPartCollection myParts = new EditorPartCollection(list);
    foreach (EditorPart editor in myParts)
    {
      editor.BackColor = System.Drawing.Color.LightBlue;
      editor.Description = "My " + editor.DisplayTitle + " editor.";
    }

    // Use the IndexOf property to locate an EditorPart control.
    int propertyGridPart = myParts.IndexOf(PropertyGridEditorPart1);
    myParts[propertyGridPart].ChromeType = PartChromeType.TitleOnly;

    // Use the Contains method to see if an EditorPart exists.
    if(!myParts.Contains(LayoutEditorPart1))
      LayoutEditorPart1.BackColor = System.Drawing.Color.LightYellow;
    
    // Use the CopyTo method to create an array of EditorParts.
    EditorPart[] partArray = new EditorPart[3];
    partArray[0] = LayoutEditorPart1;
    myParts.CopyTo(partArray,1);
    Label1.Text = "<h3>EditorParts in Custom Array</h3>";
    foreach (EditorPart ePart in partArray)
    {
      Label1.Text += ePart.Title + "<br />";
    }

  }

</script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

  Protected Sub Button1_Click(ByVal sender As Object, _
    ByVal e As EventArgs)
    
    Dim list As New ArrayList(2)
    list.Add(AppearanceEditorPart1)
    list.Add(PropertyGridEditorPart1)
    ' Pass an ICollection object to the constructor.
    Dim myParts As New EditorPartCollection(list)
    Dim editor As EditorPart
    For Each editor In myParts
      editor.BackColor = System.Drawing.Color.LightBlue
      editor.Description = "My " + editor.DisplayTitle + " editor."
    Next editor
    
    ' Use the IndexOf property to locate an EditorPart control.
    Dim propertyGridPart As Integer = _
      myParts.IndexOf(PropertyGridEditorPart1)
    myParts(propertyGridPart).ChromeType = PartChromeType.TitleOnly
    
    ' Use the Contains method to see if an EditorPart exists.
    If Not myParts.Contains(LayoutEditorPart1) Then
      LayoutEditorPart1.BackColor = System.Drawing.Color.LightYellow
    End If
    
    ' Use the CopyTo method to create an array of EditorParts.
    Dim partArray(2) As EditorPart
    partArray(0) = LayoutEditorPart1
    myParts.CopyTo(partArray, 1)
    Label1.Text = "<h3>EditorParts in Custom Array</h3>"
    Dim ePart As EditorPart
    For Each ePart In partArray
      Label1.Text += ePart.Title + "<br />"
    Next ePart

  End Sub

</script>

Lorsque vous chargez la page dans un navigateur, vous pouvez basculer la page en mode édition en sélectionnant Modifier dans le contrôle de liste déroulante Mode d’affichage . Vous pouvez cliquer sur le menu des verbes (flèche vers le bas) dans la barre de titre du TextDisplayWebPart contrôle, puis cliquer sur Modifier pour modifier le contrôle. Lorsque l’interface utilisateur de modification est visible, vous pouvez voir tous les EditorPart contrôles. Si vous cliquez sur le bouton Créer EditorPartCollection , vous remarquerez que la couleur d’arrière-plan du LayoutEditorPart1 contrôle est différente des autres contrôles, car elle ne fait pas partie de l’objet EditorPartCollection .

Remarques

La Contains méthode détermine si un contrôle spécifique EditorPart se trouve déjà dans l’objet EditorPartCollection .

S’applique à

Voir aussi