TreeNode.FromHandle Method (TreeView, IntPtr)
Returns the tree node with the specified handle and assigned to the specified tree view control.
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
The handle of the tree node.
When a node is added to the TreeView.Nodes collection, the TreeView control sends an NM_CUSTOMDRAW notification before the node handle is available. If you override the WndProc method of the TreeView to provide custom drawing in response to this notification, you should always check the return value of this method for null before you attempt to access the node.
The following code 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 requires that 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.
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
Available since 1.1