TreeNode.Handle Property
Gets the handle of the tree node.
[Visual Basic] Public ReadOnly Property Handle As IntPtr [C#] public IntPtr Handle {get;} [C++] public: __property IntPtr get_Handle(); [JScript] public function get Handle() : IntPtr;
Property Value
The tree node handle.
Remarks
If a handle is not already created when the Handle property is referenced, it is created.
Example
[Visual Basic, C#, C++] The following example gets the TreeNode that was collapsed and creates a copy of it using its Handle property. The original TreeNode is removed from the TreeNodeCollection and the copy is added to the collection. This example assumes you have a Form with a TreeView control on it. The TreeView control should have two or more root nodes, each having at least one child node.
[Visual Basic] 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 [C#] 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); } [C++] 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, S"Copy" ); // Remove the e.Node so it can be replaced with tn. e->Node->Remove(); // Add tn to the TreeNodeCollection. treeView1->Nodes->Add(tn); }
[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button
in the upper-left corner of the page.
Requirements
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family
See Also
TreeNode Class | TreeNode Members | System.Windows.Forms Namespace