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 控件。 如果单击“ 创建 EditorPartCollection ”按钮,你会注意到自定义数组中所有控件的标题列在页面底部附近。

注解

CopyTo如果想要创建自定义数组,该数组可以包含EditorPart对象中的EditorPartCollection控件、这些控件的子集或这些控件的超集,则此方法非常有用。

适用于

另请参阅