EditorPartCollection.IndexOf(EditorPart) Método

Definição

Devolve a posição de um membro específico da coleção.

public:
 int IndexOf(System::Web::UI::WebControls::WebParts::EditorPart ^ editorPart);
public int IndexOf(System.Web.UI.WebControls.WebParts.EditorPart editorPart);
member this.IndexOf : System.Web.UI.WebControls.WebParts.EditorPart -> int
Public Function IndexOf (editorPart As EditorPart) As Integer

Parâmetros

editorPart
EditorPart

E EditorPart isso é um membro da coleção.

Devoluções

Um inteiro que corresponde ao índice de um EditorPart controlo na coleção.

Exemplos

O seguinte exemplo de código demonstra como usar o IndexOf método para localizar um EditorPart controlo num EditorPartCollection objeto. 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 EditorPartCollection objeto e depois usa o IndexOf método para localizar o PropertyGridEditorPart1 controlo na coleção e definir a sua ChromeType propriedade.

<!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 o PropertyGridEditorPart1 controlo, que fica perto do fundo da página, tem um título mas sem borda.

Observações

O IndexOf método é útil se tiver vários EditorPart controlos numa página de Web Parts e precisar de localizar um controlo específico na coleção.

Aplica-se a

Ver também