Share via


EditorPartCollection.IndexOf(EditorPart) Método

Definición

Devuelve la posición de un miembro determinado de la colección.

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

EditorPart que es miembro de la colección.

Devoluciones

Int32

Un entero que corresponde al índice de un control EditorPart de la colección.

Ejemplos

En el ejemplo de código siguiente se muestra cómo usar el IndexOf método para buscar un EditorPart control en un EditorPartCollection objeto . Para obtener el código completo necesario para ejecutar el ejemplo, consulte la sección Ejemplo de la información general de la EditorPartCollection clase.

El código del Button1_Click evento crea un EditorPartCollection objeto y, a continuación, usa el IndexOf método para buscar el PropertyGridEditorPart1 control en la colección y establecer su ChromeType propiedad.

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

Al cargar la página en un explorador, puede cambiar la página al modo de edición seleccionando Editar en el control de lista desplegable Modo de visualización. Puede hacer clic en el menú verbos (la flecha hacia abajo) en la barra de título del TextDisplayWebPart control y hacer clic en Editar para editar el control. Cuando la interfaz de usuario (UI) de edición está visible, puede ver todos los EditorPart controles. Si hace clic en el botón Crear EditorPartCollection , observará que el PropertyGridEditorPart1 control, que está cerca de la parte inferior de la página, tiene un título pero ningún borde.

Comentarios

El IndexOf método es útil si tiene varios EditorPart controles en una página de elementos web y necesita buscar un control determinado en la colección.

Se aplica a

Consulte también