EditorPartCollection.Contains(EditorPart) メソッド

定義

特定のコントロールがコレクション内にあるかどうかを示す値を返します。

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

パラメーター

editorPart
EditorPart

コレクションのメンバーとしてステータスがテストされる EditorPart

戻り値

EditorPart がコレクション内にあるかどうかを示すブール値。

次のコード例では、特定 EditorPart のコントロールが オブジェクト内にあるかどうかを判断する方法を EditorPartCollection 示します。 この例を実行するために必要な完全なコードについては、クラスの概要の「例」セクションを EditorPartCollection 参照してください。

イベント内のButton1_Clickコードは、他のコントロールをLayoutEditorPart1EditorPartCollection追加するときに、 オブジェクトにコントロールを追加しません。 コントロールが LayoutEditorPart1 コレクションに含まれていないことを確認するために、コードでは メソッドを Contains 使用します。

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

ブラウザーでページを読み込むときは、[表示モード] ドロップダウン リスト コントロールの [編集] を選択して、ページを編集モードに切り替えることができます。 コントロールのタイトル バー TextDisplayWebPart にある動詞メニュー (下向き矢印) をクリックし、[ 編集 ] をクリックしてコントロールを編集できます。 編集ユーザー インターフェイス (UI) が表示されると、すべてのコントロールが EditorPart 表示されます。 [ EditorPartCollection の作成 ] ボタンをクリックすると、コントロールの背景色はオブジェクトの LayoutEditorPart1 一部ではないので、他の EditorPartCollection コントロールとは異なることがわかります。

注釈

メソッドは Contains 、特定 EditorPart のコントロールがオブジェクトに既に EditorPartCollection 存在するかどうかを決定します。

適用対象

こちらもご覧ください