TreeNode.FromHandle(TreeView, IntPtr) Método

Definición

Devuelve el nodo de árbol que tiene el identificador especificado y que está asignado al control de vista de árbol especificado.Returns the tree node with the specified handle and assigned to the specified tree view control.

public:
 static System::Windows::Forms::TreeNode ^ FromHandle(System::Windows::Forms::TreeView ^ tree, IntPtr handle);
public static System.Windows.Forms.TreeNode FromHandle (System.Windows.Forms.TreeView tree, IntPtr handle);
static member FromHandle : System.Windows.Forms.TreeView * nativeint -> System.Windows.Forms.TreeNode
Public Shared Function FromHandle (tree As TreeView, handle As IntPtr) As TreeNode

Parámetros

tree
TreeView

TreeView que contiene el nodo de árbol.The TreeView that contains the tree node.

handle
IntPtr

Identificador del nodo de árbol.The handle of the tree node.

Devoluciones

TreeNode que representa el nodo de árbol que está asignado al control de TreeView especificado y que tiene el identificador especificado.A TreeNode that represents the tree node assigned to the specified TreeView control with the specified handle.

Ejemplos

En el ejemplo de código siguiente TreeNode se obtiene el que se contrajo y se crea una copia Handle de él mediante su propiedad.The following code example gets the TreeNode that was collapsed and creates a copy of it using its Handle property. El original TreeNode se quita TreeNodeCollectionde y la copia se agrega a la colección.The original TreeNode is removed from the TreeNodeCollection, and the copy is added to the collection. Este ejemplo requiere que tenga un Form TreeView control en él.This example requires that you have a Form with a TreeView control on it. El TreeView control debe tener dos o más nodos raíz, cada uno con al menos un nodo secundario.The TreeView control should have two or more root nodes, each having at least one child node.

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 

Comentarios

Cuando se agrega un nodo a la TreeView.Nodes colección, el TreeView control envía una notificación NM_CUSTOMDRAW antes de que el identificador del nodo esté disponible.When a node is added to the TreeView.Nodes collection, the TreeView control sends an NM_CUSTOMDRAW notification before the node handle is available. Si invalida el WndProc método TreeView de para proporcionar el dibujo personalizado en respuesta a esta notificación, siempre debe comprobar el valor devuelto por null este método antes de intentar tener acceso al nodo.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.

Se aplica a

Consulte también: