TreeNode.Toggle 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
将树节点切换为展开或折叠状态。
public:
void Toggle();
public void Toggle ();
member this.Toggle : unit -> unit
Public Sub Toggle ()
示例
下面的代码示例删除 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
注解
将树节点切换为与其当前状态相反的状态(展开或折叠)。