EditorPartCollection.CopyTo(EditorPart[], Int32) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
將集合複製到一個 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 控制項。 如果你點擊 Create EditorPartCollection 按鈕,你會注意到自訂陣列中所有控制項的標題都列在頁面底部附近。
備註
當你想建立一個自訂陣列,能包含CopyTo物件中的EditorPart控制項、控制項的子集,或控制項的超集時,這個EditorPartCollection方法非常有用。