EditorPartCollection.CopyTo(EditorPart[], Int32) Método

Definição

Copia a coleção para um conjunto de EditorPart controlos.

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)

Parâmetros

array
EditorPart[]

An EditorPart para conter a coleção copiada de controlos.

index
Int32

O ponto de partida no array onde colocar o conteúdo da coleção.

Exemplos

O exemplo de código seguinte demonstra como usar o CopyTo método para criar um array personalizado de EditorPart controlos. Para o código completo necessário para executar o exemplo, consulte a secção Exemplo da EditorPartCollection visão geral da classe.

O código no Button1_Click evento cria um array de EditorPart controlos, adiciona o LayoutEditorPart1 controlo ao array e depois usa o CopyTo método para copiar os controlos do EditorPartCollection objeto para o array.

<!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>

Quando carregas a página num navegador, podes mudar a página para o modo de edição selecionando Editar no controlo de lista suspensa do Modo de Exibição . Podes clicar no menu de verbos (a seta para baixo) na barra de título do TextDisplayWebPart controlo e clicar em Editar para editar o controlo. Quando a interface de utilizador de edição (UI) está visível, pode ver todos os EditorPart controlos. Se clicar no botão Criar EditorParteCollection , notará que os títulos de todos os controlos no array personalizado estão listados perto do fundo da página.

Observações

O CopyTo método é útil quando se quer criar um array personalizado que possa conter os EditorPart controlos no EditorPartCollection objeto, um subconjunto desses controlos ou um superconjunto desses controlos.

Aplica-se a

Ver também