語言

EditorPartCollection 建構函式

定義

初始化 EditorPartCollection 類別的新執行個體。

多載

名稱 Description
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 來建立新的 S 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 控制項。 你點擊 Create 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

一個ICollectionEditorPart控制不在區域內,而是以程式化方式建立的。

另請參閱

適用於