TreeNode.Handle 属性

定义

获取树节点的句柄。

public:
 property IntPtr Handle { IntPtr get(); };
public IntPtr Handle { get; }
[System.ComponentModel.Browsable(false)]
public IntPtr Handle { get; }
member this.Handle : nativeint
[<System.ComponentModel.Browsable(false)>]
member this.Handle : nativeint
Public ReadOnly Property Handle As IntPtr

属性值

IntPtr

nativeint

树节点句柄。

属性

示例

下面的代码示例获取 TreeNode 已折叠并使用其 Handle 属性创建副本。 原始 TreeNode 副本已从集合 TreeNodeCollection中删除,并将副本添加到集合中。 此示例要求你具有 Form 一个 TreeView 控件。 控件 TreeView 应具有两个或更多根节点,每个节点至少有一个子节点。

private:
   void treeView1_AfterCollapse( Object^ /*sender*/, TreeViewEventArgs^ e )
   {
      // Create a copy of the e.Node from its Handle.
      TreeNode^ tn = TreeNode::FromHandle( e->Node->TreeView, e->Node->Handle );
      tn->Text = String::Concat( tn->Text, "Copy" );

      // Remove the e.Node so it can be replaced with tn.
      e->Node->Remove();

      // Add tn to the TreeNodeCollection.
      treeView1->Nodes->Add( tn );
   }
private void treeView1_AfterCollapse(object sender, TreeViewEventArgs e)
{
   // Create a copy of the e.Node from its Handle.
   TreeNode tn = TreeNode.FromHandle(e.Node.TreeView, e.Node.Handle);
   tn.Text += "Copy";
   // Remove the e.Node so it can be replaced with tn.
   e.Node.Remove();
   // Add tn to the TreeNodeCollection.
   treeView1.Nodes.Add(tn);
}
Private Sub treeView1_AfterCollapse(sender As Object, _
  e As TreeViewEventArgs) Handles treeView1.AfterCollapse
   ' Create a copy of the e.Node from its Handle.
   Dim tn As TreeNode = TreeNode.FromHandle(e.Node.TreeView, e.Node.Handle)
   tn.Text += "Copy"
   ' Remove the e.Node so it can be replaced with tn.
   e.Node.Remove()
   ' Add tn to the TreeNodeCollection.
   treeView1.Nodes.Add(tn)
End Sub

注解

如果引用属性时 Handle 尚未创建句柄,则会创建该句柄。

适用于