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 空實例。 這個建構函式的多載會由 EditorZoneCreateEditorParts 方法中的 類別在內部使用,以建立空的集合物件。 然後,區域會建立子領域範本中宣告之所有 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 程式碼會建立 物件、將頁面中三 EditorPartArrayList 控制項的兩個控制項新增至 物件,然後使用 建構函式建立新的 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 控制項。 按一下 [ 建立編輯器][PartCollection ] 按鈕,以查看新增至物件的兩 EditorPart 個控制項的效果 EditorPartCollection

備註

EditorPartCollection 構函式會初始化 類別的實例, EditorPartCollection 並傳入 控制項的 EditorPart 集合。 這是建構函式的 EditorPartCollection 其中一個多載,可用來建立新的 EditorPartCollection 物件,並將控制項加入 EditorPart 其中。

即使 EditorPartCollection 建構函式所建立的實例是唯讀的,您仍然可以以程式設計方式存取集合中的個別 EditorPart 控制項,並呼叫其屬性和方法。

使用 EditorPartCollection 建構函式的其中一個常見案例是,如果您想要在一組 EditorPart 整個控制項上執行一些批次作業,例如變更相關群組的內容、外觀或位置。

另一個使用建 EditorPartCollection 構函式的常見案例是開發您想要與伺服器控制項建立關聯的自訂 EditorPart 控制項,讓使用者可以在控制項上編輯自訂屬性。 在此案例中,您的伺服器控制項必須實 IWebEditable 作 介面,而且作為該工作的一部分,它必須實作 CreateEditorParts 方法。 在該方法中,若要讓自訂 EditorPart 控制項編輯服務器控制項,您必須將 EditorPart 控制項新增至 ICollection 實例,例如 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,是以程式設計方式建立的。

另請參閱

適用於