TreeNode.Toggle TreeNode.Toggle TreeNode.Toggle TreeNode.Toggle Method

Definición

Alterna el estado del nodo de árbol entre expandido y contraído.Toggles the tree node to either the expanded or collapsed state.

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

Ejemplos

El código siguiente en el ejemplo se quita un TreeNode cuando el usuario hace clic con el botón del mouse sobre él y alterna desde expanden a contraída cuando el usuario hace clic en la rueda del mouse sobre él.The following code example removes a TreeNode when the user right-clicks the mouse over it and toggles it from expanded to collapsed when the user clicks the mouse wheel over it. En este ejemplo requiere que haya un Form con un TreeView control en él.This example requires that you have a Form with a TreeView control on it. El TreeView debe tener dos o más nodos del árbol raíz, cada uno con al menos un nodo secundario.The TreeView should have two or more root tree nodes, each having at least one child node.

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 cambia al estado opuesto su estado actual, ya sea expandido o contraído.The tree node is toggled to the state opposite its current state, either expanded or collapsed.

Nota

El estado de un TreeNode se conserva.The state of a TreeNode is persisted. Por ejemplo, si el siguiente nivel de nodos secundarios no se ha contraído anteriormente, cuando el Expand se llama al método, los nodos secundarios aparecen en su estado expandido previamente.For example, if the next level of child nodes was not collapsed previously, when the Expand method is called, the child nodes appear in their previously expanded state.

Se aplica a

Consulte también: