TreeNode.FromHandle(TreeView, IntPtr) Metodo

Definizione

Restituisce il nodo della struttura ad albero con l'handle specificato e assegnato al controllo di visualizzazione ad albero specificato.

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

Parametri

tree
TreeView

Controllo TreeView che contiene il nodo della struttura ad albero.

handle
IntPtr

nativeint

Handle del nodo della struttura ad albero.

Restituisce

TreeNode

Oggetto TreeNode che rappresenta il nodo della struttura ad albero assegnato al controllo TreeView specificato con l'handle specificato.

Esempio

L'esempio di codice seguente ottiene l'oggetto TreeNode compresso e ne crea una copia usando la relativa Handle proprietà. L'originale TreeNode viene rimosso dall'oggetto TreeNodeCollectione la copia viene aggiunta alla raccolta. In questo esempio è necessario disporre di un Form controllo con un TreeView controllo. Il TreeView controllo deve avere due o più nodi radice, ognuno con almeno un nodo figlio.

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

Commenti

Quando un nodo viene aggiunto alla TreeView.Nodes raccolta, il TreeView controllo invia una notifica NM_CUSTOMDRAW prima che sia disponibile l'handle del nodo. Se si esegue l'override TreeView del WndProc metodo di per fornire disegno personalizzato in risposta a questa notifica, è consigliabile controllare sempre il valore restituito di questo metodo prima null di tentare di accedere al nodo.

Si applica a

Vedi anche