TreeNode.Toggle Metoda

Definicja

Przełącza węzeł drzewa do stanu rozwiniętego lub zwiniętego.

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

Przykłady

Poniższy przykład kodu usuwa TreeNode element, gdy użytkownik kliknie prawym przyciskiem myszy nad nim i przełączy go z rozwiniętego do zwiniętego, gdy użytkownik kliknie nad nim kółko myszy. W tym przykładzie jest wymagana Form kontrolka z kontrolką TreeView . Powinien TreeView mieć co najmniej dwa węzły drzewa głównego, z których każdy ma co najmniej jeden węzeł podrzędny.

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

Uwagi

Węzeł drzewa jest przełączany do stanu naprzeciwko bieżącego stanu, rozwiniętego lub zwiniętego.

Uwaga

Stan TreeNode obiektu jest utrwalany. Jeśli na przykład następny poziom węzłów podrzędnych nie został wcześniej zwinięty, po Expand wywołaniu metody węzły podrzędne są wyświetlane w ich wcześniej rozwiniętym stanie.

Dotyczy

Zobacz też