Share via


EditorPartCollection.Contains(EditorPart) Metodo

Definizione

Restituisce un valore che indica la presenza di un determinato controllo nell'insieme.

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

Parametri

editorPart
EditorPart

Controllo EditorPart di cui verificare lo stato di membro dell'insieme.

Restituisce

Boolean

Valore booleano che indica se il controllo EditorPart è contenuto nell'insieme.

Esempio

Nell'esempio di codice seguente viene illustrato come determinare se un determinato EditorPart controllo si trova in un EditorPartCollection oggetto . Per il codice completo necessario per eseguire l'esempio, vedere la sezione Esempio della panoramica della EditorPartCollection classe.

Il codice nell'evento Button1_Click non aggiunge il LayoutEditorPart1 controllo all'oggetto EditorPartCollection quando aggiunge gli altri controlli. Per verificare che il LayoutEditorPart1 controllo non si trova nella raccolta, il codice usa il Contains metodo .

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

Quando si carica la pagina in un browser, è possibile passare alla modalità di modifica selezionando Modifica nel controllo elenco a discesa Modalità di visualizzazione . È possibile fare clic sul menu dei verbi (freccia verso il basso) nella barra del titolo del TextDisplayWebPart controllo e fare clic su Modifica per modificare il controllo. Quando l'interfaccia utente di modifica è visibile, è possibile visualizzare tutti i EditorPart controlli. Se si fa clic sul pulsante Crea EditorPartCollection , si noterà che il colore di sfondo del LayoutEditorPart1 controllo è diverso dagli altri controlli, perché non fa parte dell'oggetto EditorPartCollection .

Commenti

Il Contains metodo determina se un controllo specifico EditorPart è già presente nell'oggetto EditorPartCollection .

Si applica a

Vedi anche