TreeNode.Remove 方法

定义

从树视图控件中移除当前树节点。

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

示例

下面的代码示例删除 TreeNode 用户右键单击鼠标上方的鼠标,并在用户单击鼠标滚轮时将其从展开切换为折叠。 此示例要求你具有FormTreeView控件。 应 TreeView 具有两个或多个根树节点,每个节点至少有一个子节点。

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

注解

When 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 但仍附加到此树节点。

适用于

另请参阅