TreeNode.Remove TreeNode.Remove TreeNode.Remove TreeNode.Remove Method

定義

從樹狀檢視控制項移除目前的樹狀節點。Removes the current tree node from the tree view control.

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

範例

下列程式碼範例會TreeNode在使用者按一下滑鼠右鍵時移除,並在使用者按下滑鼠滾輪時,將它從展開切換為折迭。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. 此範例會要求您擁有Form TreeView具有控制項的。This example requires that you have a Form with a TreeView control on it. TreeView應該有兩個或多個根樹狀節點,每一個都至少有一個子節點。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

備註

呼叫方法時,會從TreeView移除樹狀節點,以及指派給的TreeNode任何子樹狀節點。 RemoveWhen the Remove method is called, the tree node, and any child tree nodes that are assigned to the TreeNode, are removed from the TreeView. 已移除的子節點會從移除TreeView ,但仍會附加到這個樹狀節點。The removed child nodes are removed from the TreeView but are still attached to this tree node.

適用於

另請參閱