TreeNode.Toggle Método

Definición

Alterna el estado del nodo de árbol entre expandido y contraído.

public:
 void Toggle();
public void Toggle ();
member this.Toggle : unit -> unit
Public Sub Toggle ()

Ejemplos

En el ejemplo de código siguiente se quita un TreeNode elemento cuando el usuario hace clic con el botón derecho en el mouse sobre él y lo alterna de expandido a contraído cuando el usuario hace clic en la rueda del mouse sobre él. En este ejemplo se requiere que tenga un Form con un TreeView control en él. TreeView Debe tener dos o más nodos de árbol raíz, cada uno con al menos un nodo secundario.

private:
   void treeView1_MouseDown( Object^ /*sender*/, MouseEventArgs^ e )
   {
      switch ( e->Button )
      {
         // Remove the TreeNode under the mouse cursor
         // if the right mouse button was clicked.
         case ::MouseButtons::Right:
            treeView1->GetNodeAt( e->X, e->Y )->Remove();
            break;

         // Toggle the TreeNode under the mouse cursor
         // if the middle mouse button (mouse wheel) was clicked.
         case ::MouseButtons::Middle:
            treeView1->GetNodeAt( e->X, e->Y )->Toggle();
            break;
      }
   }
private void treeView1_MouseDown(object sender, MouseEventArgs e)
{
   switch(e.Button)
   {
      // Remove the TreeNode under the mouse cursor 
      // if the right mouse button was clicked. 
      case MouseButtons.Right:
         treeView1.GetNodeAt(e.X, e.Y).Remove();
         break;
      
      // Toggle the TreeNode under the mouse cursor 
      // if the middle mouse button (mouse wheel) was clicked. 
      case MouseButtons.Middle:
         treeView1.GetNodeAt(e.X, e.Y).Toggle();
         break;
   }
}
Private Sub treeView1_MouseDown(sender As Object, _
  e As MouseEventArgs) Handles treeView1.MouseDown
   Select Case e.Button
      ' Remove the TreeNode under the mouse cursor 
      ' if the right mouse button was clicked. 
      Case MouseButtons.Right
         treeView1.GetNodeAt(e.X, e.Y).Remove()
      
      ' Toggle the TreeNode under the mouse cursor 
      ' if the middle mouse button (mouse wheel) was clicked. 
      Case MouseButtons.Middle
         treeView1.GetNodeAt(e.X, e.Y).Toggle()
   End Select
End Sub

Comentarios

El nodo de árbol se alterna con el estado opuesto a su estado actual, ya sea expandido o contraído.

Nota

El estado de un TreeNode objeto se conserva. Por ejemplo, si el siguiente nivel de nodos secundarios no se contraía anteriormente, cuando se llama al Expand método , los nodos secundarios aparecen en su estado expandido previamente.

Se aplica a

Consulte también