语言

EditorPartCollection 构造函数

定义

初始化 EditorPartCollection 类的新实例。

重载

名称 说明
EditorPartCollection()

初始化类的 EditorPartCollection 空新实例。

EditorPartCollection(ICollection)

通过传入EditorPartCollection控件集合ICollection来初始化类的新实例EditorPart。

EditorPartCollection(EditorPartCollection, ICollection)

通过传入EditorPartCollection控件集合和EditorPartCollection附加EditorPart控件的ICollection集合来初始化类的新实例EditorPart。

EditorPartCollection()

初始化类的 EditorPartCollection 空新实例。

public:
 EditorPartCollection();
public EditorPartCollection();
Public Sub New ()

注解

构造 EditorPartCollection 函数初始化类的 EditorPartCollection 空实例。 构造函数的此重载由 EditorZone 其方法中的类在 CreateEditorParts 内部用于创建空集合对象。 然后,区域创建子区域模板中声明的所有 EditorPart 控件的实例,并使用内部方法将它们添加到集合。

不能使用此构造函数重EditorPartCollection载创建控件的新实例并将其添加到EditorPartCollection该实例EditorPart。 必须改为对 EditorPartCollection 构造函数使用另一个重载。

另请参阅

适用于

EditorPartCollection(ICollection)

通过传入EditorPartCollection控件集合ICollection来初始化类的新实例EditorPart。

public:
 EditorPartCollection(System::Collections::ICollection ^ editorParts);
public EditorPartCollection(System.Collections.ICollection editorParts);
new System.Web.UI.WebControls.WebParts.EditorPartCollection : System.Collections.ICollection -> System.Web.UI.WebControls.WebParts.EditorPartCollection
Public Sub New (editorParts As ICollection)

参数

editorParts
ICollection

控件ICollection。EditorPart

示例

下面的代码示例演示如何创建自定义 EditorPartCollection ,即使集合是只读的,仍执行批处理操作来更改集合中的单个 EditorPart 控件。 有关运行示例所需的完整代码,请参阅类概述的 EditorPartCollection “示例”部分。

事件中的Button1_Click代码创建一个对象,将页面中的三ArrayList个控件中的两个EditorPart添加到对象,然后使用构造函数创建新EditorPartCollection对象EditorPartCollection。 它还演示了如何对基础 EditorPart 控件进行更改,即使集合是只读的。

<!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”按钮可查看添加到EditorPart对象的两EditorPartCollection个控件的效果。

注解

构造 EditorPartCollection 函数初始化类的 EditorPartCollection 实例并传入控件集合 EditorPart 。 这是可用于创建新EditorPartCollection对象的构造函数的EditorPartCollection一个重载,并向其添加EditorPart控件。

即使构造函数创建的实例是只读的 EditorPartCollection ,你仍然可以以编程方式访问集合中的单个 EditorPart 控件,并调用其属性和方法。

使用构造函数的 EditorPartCollection 一个常见方案是,如果要对整个控件集 EditorPart 执行一些批处理操作,例如更改相关组的内容、外观或位置。

使用 EditorPartCollection 构造函数的另一个常见方案是开发要与服务器控件关联的自定义 EditorPart 控件,以便用户可以编辑控件上的自定义属性。 在此方案中,服务器控件必须实现 IWebEditable 接口,并且作为该任务的一部分,它必须实现 CreateEditorParts 该方法。 在该方法中,若要使自定义EditorPart控件能够编辑服务器控件,必须将控件添加到EditorPartICollection实例(如ArrayList对象)。 然后,可以将控件的 EditorPart 集合传递给 EditorPartCollection 构造函数以创建一个新 EditorPartCollection 对象, EditorZoneBase 该区域使用该对象来设置所有控件并开始编辑过程。

另请参阅

适用于

EditorPartCollection(EditorPartCollection, ICollection)

通过传入EditorPartCollection控件集合和EditorPartCollection附加EditorPart控件的ICollection集合来初始化类的新实例EditorPart。

public:
 EditorPartCollection(System::Web::UI::WebControls::WebParts::EditorPartCollection ^ existingEditorParts, System::Collections::ICollection ^ editorParts);
public EditorPartCollection(System.Web.UI.WebControls.WebParts.EditorPartCollection existingEditorParts, System.Collections.ICollection editorParts);
new System.Web.UI.WebControls.WebParts.EditorPartCollection : System.Web.UI.WebControls.WebParts.EditorPartCollection * System.Collections.ICollection -> System.Web.UI.WebControls.WebParts.EditorPartCollection
Public Sub New (existingEditorParts As EditorPartCollection, editorParts As ICollection)

参数

existingEditorParts
EditorPartCollection

ICollection区域中的现有EditorPart控件。

editorParts
ICollection

ICollection EditorPart不在区域中但以编程方式创建的控件。

另请参阅

适用于