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

返回

Boolean

一个布尔值,指示集合中是否存在 EditorPart

示例

下面的代码示例演示如何确定特定 EditorPart 控件是否位于对象中 EditorPartCollection 。 有关运行示例所需的完整代码,请参阅类概述的示例 EditorPartCollection 部分。

事件中的Button1_Click代码在添加其他控件时不会将控件添加到EditorPartCollectionLayoutEditorPart1对象。 若要确认 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

适用于

另请参阅