Taal

EditorPartCollection.Contains(EditorPart) Methode

Definitie

Retourneert een waarde die aangeeft of een bepaald besturingselement zich in de verzameling bevindt.

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

Parameters

editorPart
EditorPart

De EditorPart test voor de status ervan als lid van de verzameling.

Retouren

Een Booleaanse waarde die aangeeft of de EditorPart verzameling zich in de verzameling bevindt.

Voorbeelden

In het volgende codevoorbeeld ziet u hoe u kunt bepalen of een bepaald EditorPart besturingselement zich in een EditorPartCollection object bevindt. Zie de sectie Voorbeeld van het EditorPartCollection klassenoverzicht voor de volledige code die nodig is om het voorbeeld uit te voeren.

De code in de Button1_Click gebeurtenis voegt het LayoutEditorPart1 besturingselement niet toe aan het EditorPartCollection object wanneer het andere besturingselementen toevoegt. Om te bevestigen dat het LayoutEditorPart1 besturingselement zich niet in de verzameling bevindt, gebruikt de code de Contains methode.

<!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>

Wanneer u de pagina in een browser laadt, kunt u de pagina overschakelen naar de bewerkingsmodus door Bewerken te selecteren in de vervolgkeuzelijst Weergavemodus . U kunt op het menu Werkwoorden (de pijl-omlaag) in de titelbalk van het TextDisplayWebPart besturingselement klikken en op Bewerken klikken om het besturingselement te bewerken. Wanneer de gebruikersinterface (UI) voor bewerken zichtbaar is, kunt u alle EditorPart besturingselementen zien. Als u op de knop EditorPartCollection maken klikt, ziet u dat de achtergrondkleur van het LayoutEditorPart1 besturingselement verschilt van de andere besturingselementen, omdat het geen deel uitmaakt van het EditorPartCollection object.

Opmerkingen

De Contains methode bepaalt of een specifiek EditorPart besturingselement zich al in het EditorPartCollection object bevindt.

Van toepassing op

Zie ook