Bagikan melalui


EditorPartCollection.Contains(EditorPart) Metode

Definisi

Mengembalikan nilai yang menunjukkan apakah kontrol tertentu berada dalam koleksi.

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

Parameter

editorPart
EditorPart

Sedang EditorPart diuji statusnya sebagai anggota koleksi.

Mengembalikan

Nilai Boolean yang menunjukkan apakah EditorPart ada dalam koleksi.

Contoh

Contoh kode berikut menunjukkan cara menentukan apakah kontrol tertentu EditorPart berada dalam EditorPartCollection objek. Untuk kode lengkap yang diperlukan untuk menjalankan contoh, lihat bagian Contoh dari EditorPartCollection gambaran umum kelas.

Kode dalam Button1_Click peristiwa tidak menambahkan LayoutEditorPart1 kontrol ke EditorPartCollection objek saat menambahkan kontrol lainnya. Untuk mengonfirmasi bahwa LayoutEditorPart1 kontrol tidak ada dalam koleksi, kode menggunakan Contains metode .

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

Saat memuat halaman di browser, Anda dapat mengalihkan halaman ke mode edit dengan memilih Edit di kontrol daftar drop-down Mode Tampilan . Anda dapat mengklik menu kata kerja (panah ke bawah) di bilah TextDisplayWebPart judul kontrol, dan klik Edit untuk mengedit kontrol. Saat antarmuka pengguna pengeditan (UI) terlihat, Anda dapat melihat semua EditorPart kontrol. Jika Anda mengklik tombol Buat EditorPartCollection , Anda akan melihat bahwa warna LayoutEditorPart1 latar belakang kontrol berbeda dari kontrol lain, karena itu bukan bagian EditorPartCollection dari objek.

Keterangan

Metode Contains menentukan apakah kontrol tertentu EditorPart sudah ada di EditorPartCollection objek .

Berlaku untuk

Lihat juga