共用方式為


EditorPartCollection.CopyTo(EditorPart[], Int32) 方法

定義

複製集合至 EditorPart 控制項的陣列。

public:
 void CopyTo(cli::array <System::Web::UI::WebControls::WebParts::EditorPart ^> ^ array, int index);
public void CopyTo (System.Web.UI.WebControls.WebParts.EditorPart[] array, int index);
member this.CopyTo : System.Web.UI.WebControls.WebParts.EditorPart[] * int -> unit
Public Sub CopyTo (array As EditorPart(), index As Integer)

參數

array
EditorPart[]

要包含控制項之複製集合的 EditorPart

index
Int32

放置集合內容的陣列起點。

範例

下列程式代碼範例示範如何使用 CopyTo 方法來建立控件的 EditorPart 自定義數位列。 如需執行範例所需的完整程式碼,請參閱類別概觀的 EditorPartCollection 範例一節。

事件中的 Button1_Click 程式代碼會建立控件數位列 EditorPart 、將 LayoutEditorPart1 控件加入數位,然後使用 CopyTo 方法將控件從 EditorPartCollection 物件複製到數位列。

<!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控件、這些控件子集或這些控件超集的自定義數位時,此方法CopyTo很有用。

適用於

另請參閱