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

注解

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

适用于

另请参阅