TreeNode.Collapse TreeNode.Collapse TreeNode.Collapse TreeNode.Collapse Method

定義

摺疊 TreeNodeCollapses the TreeNode.

多載

Collapse() Collapse() Collapse() Collapse()

收合樹狀節點。Collapses the tree node.

Collapse(Boolean) Collapse(Boolean) Collapse(Boolean) Collapse(Boolean)

摺疊 TreeNode 並選擇性地摺疊其子系。Collapses the TreeNode and optionally collapses its children.

Collapse() Collapse() Collapse() Collapse()

收合樹狀節點。Collapses the tree node.

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

範例

下列程式碼範例會在按一下按鈕時,切換選取的節點。The following code example toggles the selected node when a button is clicked. 如果選取的節點已折迭,則會展開,如果它是藉由呼叫Expand方法來擴充,則會藉由Collapse呼叫方法來折迭。If the selected node is collapsed, it is expanded, if it is expanded by calling the Expand method, it is collapsed by calling the Collapse method. 這個Form範例需要TreeView有一個具有至少一個TreeNode具有至少一個子TreeNode系之控制項的。This example requires that you have a Form with a TreeView control that has at least one TreeNode with at least one child TreeNode.

void button1_Click( Object^ /*sender*/, System::EventArgs^ /*e*/ )
{
   if ( treeView1->SelectedNode->IsExpanded )
   {
      treeView1->SelectedNode->Collapse();
      MessageBox::Show( String::Concat( treeView1->SelectedNode->Text, " tree node collapsed." ) );
   }
   else
   {
      treeView1->SelectedNode->Expand();
      MessageBox::Show( String::Concat( treeView1->SelectedNode->Text, " tree node expanded." ) );
   }
}
private void button1_Click(object sender, System.EventArgs e)
{
   if (treeView1.SelectedNode.IsExpanded)
   {
      treeView1.SelectedNode.Collapse();
      MessageBox.Show(treeView1.SelectedNode.Text + 
        " tree node collapsed.");
   }
   else
   {
      treeView1.SelectedNode.Expand();
      MessageBox.Show(treeView1.SelectedNode.Text + 
        " tree node expanded.");
   }
}
Private Sub button1_Click(sender As Object, _
  e As System.EventArgs) Handles button1.Click
   If treeView1.SelectedNode.IsExpanded Then
      treeView1.SelectedNode.Collapse()
      MessageBox.Show(treeView1.SelectedNode.Text & _ 
        " tree node collapsed.")
   Else
      treeView1.SelectedNode.Expand()
      MessageBox.Show(treeView1.SelectedNode.Text & _
        " tree node expanded.")
   End If
End Sub 

備註

方法會折迭目前TreeNode的及其子節點。 CollapseThe Collapse method collapses the current TreeNode and its child nodes. 如果您只想要折迭目前TreeNode的,請TreeNode.Collapse(Boolean)使用多載true ,傳遞以忽略其子節點。If you want to collapse only the current TreeNode, use the TreeNode.Collapse(Boolean) overload, passing true to ignore its child nodes.

注意

的狀態TreeNode會保存。The state of a TreeNode is persisted. 例如,如果先前未折迭子節點的下一個層級,則在Expand呼叫方法時,子節點會出現在先前展開的狀態中。For example, if the next level of child nodes was not collapsed previously, when the Expand method is called, the child nodes appear in their previously expanded state.

另請參閱

Collapse(Boolean) Collapse(Boolean) Collapse(Boolean) Collapse(Boolean)

摺疊 TreeNode 並選擇性地摺疊其子系。Collapses the TreeNode and optionally collapses its children.

public:
 void Collapse(bool ignoreChildren);
public void Collapse (bool ignoreChildren);
member this.Collapse : bool -> unit
Public Sub Collapse (ignoreChildren As Boolean)

參數

ignoreChildren
Boolean Boolean Boolean Boolean

若要讓子節點維持目前的狀態,則為 true;若要摺疊子節點,則為 falsetrue to leave the child nodes in their current state; false to collapse the child nodes.

備註

當您Collapse想要折true迭節點,但讓其子節點處於擴充狀態時,請使用傳遞的方法。Use the Collapse method, passing true, when you want to collapse a node but leave its child nodes in their expanded state.

適用於