TreeNode.FromHandle(TreeView, IntPtr) TreeNode.FromHandle(TreeView, IntPtr) TreeNode.FromHandle(TreeView, IntPtr) TreeNode.FromHandle(TreeView, IntPtr) Method

定義

傳回具有指定控制代碼和指派給樹狀檢視控制項的樹狀節點。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

參數

tree
TreeView TreeView TreeView TreeView

TreeView,包含樹狀節點。The TreeView that contains the tree node.

handle
IntPtr IntPtr IntPtr IntPtr

樹狀節點的控制代碼。The handle of the tree node.

傳回

TreeNode,表示樹狀節點,它被指派給具有指定控制代碼的指定 TreeView 控制項。A TreeNode that represents the tree node assigned to the specified TreeView control with the specified handle.

範例

下列程式碼範例會取得TreeNode已折迭的,並使用其Handle屬性來建立其複本。The following code example gets the TreeNode that was collapsed and creates a copy of it using its Handle property. 原始TreeNode的會TreeNodeCollection從移除,且會將複本新增至集合。The original TreeNode is removed from the TreeNodeCollection, and the copy is added to the collection. 此範例會要求您擁有Form TreeView具有控制項的。This example requires that you have a Form with a TreeView control on it. TreeView控制項應該有兩個或多個根節點,每一個都至少有一個子節點。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 

備註

當節點新增至TreeView.Nodes集合時TreeView ,控制項會在節點控制碼可供使用之前傳送 NM_CUSTOMDRAW 通知。When a node is added to the TreeView.Nodes collection, the TreeView control sends an NM_CUSTOMDRAW notification before the node handle is available. 如果您覆寫WndProc的方法TreeView ,以提供自訂繪圖來回應此通知,您應該一律在嘗試存取節點null之前,檢查這個方法的傳回值。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.

適用於

另請參閱