EditorPartCollection.Contains(EditorPart) Metod

Definition

Returnerar ett värde som anger om en viss kontroll finns i samlingen.

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

Parametrar

editorPart
EditorPart

Testas EditorPart för dess status som medlem i samlingen.

Returer

Ett booleskt värde som anger om EditorPart är i samlingen.

Exempel

Följande kodexempel visar hur du avgör om en viss EditorPart kontroll finns i ett EditorPartCollection objekt. Den fullständiga kod som krävs för att köra exemplet finns i avsnittet Exempel i klassöversikten EditorPartCollection .

Koden i Button1_Click händelsen lägger inte till LayoutEditorPart1 kontrollen i EditorPartCollection objektet när den lägger till de andra kontrollerna. För att bekräfta att LayoutEditorPart1 kontrollen inte finns i samlingen använder Contains koden metoden.

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

När du läser in sidan i en webbläsare kan du växla sidan till redigeringsläge genom att välja Redigera i listrutan Visningsläge . Du kan klicka på verbmenyn (nedåtpilen) i kontrollens TextDisplayWebPart namnlist och klicka på Redigera för att redigera kontrollen. När användargränssnittet (UI) är synligt kan du se alla EditorPart kontroller. Om du klickar på knappen Skapa EditorPartCollection ser du att kontrollens bakgrundsfärg LayoutEditorPart1 skiljer sig från de andra kontrollerna, eftersom den inte ingår i EditorPartCollection objektet.

Kommentarer

Metoden Contains avgör om en specifik EditorPart kontroll redan finns i objektet EditorPartCollection .

Gäller för

Se även