TreeNode.Remove 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
從樹狀檢視控制項移除目前的樹狀節點。
public:
void Remove();
public void Remove ();
member this.Remove : unit -> unit
Public Sub Remove ()
範例
下列程式碼範例會在 TreeNode 使用者以滑鼠右鍵按一下滑鼠上方時移除 ,並在使用者按一下滑鼠滾輪時將它從展開切換為折迭。 此範例會要求您具有 Form 控制項 TreeView 的 。 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
備註
Remove呼叫 方法時,會從 TreeView 中移除樹狀節點,以及指派給 TreeNode 的任何子樹狀節點。 移除的子節點會從 中移除, TreeView 但仍附加至這個樹狀節點。