EditorPartCollection.IndexOf(EditorPart) Método

Definição

Retorna a posição de um membro específico da coleção.Returns the position of a particular member of the collection.

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

Um EditorPart se for um membro da coleção.An EditorPart that is a member of the collection.

Retornos

Int32

Um inteiro que corresponde ao índice de um controle EditorPart na coleção.An integer that corresponds to the index of an EditorPart control in the collection.

Exemplos

O exemplo de código a seguir demonstra como usar o IndexOf método para localizar um EditorPart controle em um EditorPartCollection objeto.The following code example demonstrates how to use the IndexOf method to locate an EditorPart control in an EditorPartCollection object. Para obter o código completo necessário para executar o exemplo, consulte a seção de exemplo da EditorPartCollection classe visão geral.For the full code required to run the example, see the Example section of the EditorPartCollection class overview.

O código no Button1_Click evento cria um EditorPartCollection objeto e, em seguida, usa o IndexOf método para localizar o PropertyGridEditorPart1 controle na coleção e definir sua ChromeType propriedade.The code in the Button1_Click event creates an EditorPartCollection object, and then uses the IndexOf method to locate the PropertyGridEditorPart1 control in the collection, and set its ChromeType property.

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

Ao carregar a página em um navegador, você pode alternar a página para o modo de edição selecionando Editar no controle de lista suspensa modo de exibição .When you load the page in a browser, you can switch the page into edit mode by selecting Edit in the Display Mode drop-down list control. Você pode clicar no menu de verbos (a seta para baixo) na barra de título do TextDisplayWebPart controle e clicar em Editar para editar o controle.You can click the verbs menu (the downward arrow) in the title bar of the TextDisplayWebPart control, and click Edit to edit the control. Quando a interface do usuário de edição (IU) estiver visível, você poderá ver todos os EditorPart controles.When the editing user interface (UI) is visible, you can see all the EditorPart controls. Se você clicar no botão Criar EditorPartCollection , observará que o PropertyGridEditorPart1 controle, que está próximo à parte inferior da página, tem um título, mas sem borda.If you click the Create EditorPartCollection button, you will notice that the PropertyGridEditorPart1 control, which is near the bottom of the page, has a title but no border.

Comentários

O IndexOf método será útil se você tiver vários EditorPart controles em uma Web Parts página e precisar localizar um controle específico na coleção.The IndexOf method is useful if you have multiple EditorPart controls on a Web Parts page, and you need to locate a particular control in the collection.

Aplica-se a