共用方式為


TreeNode.FromHandle(TreeView, IntPtr) 方法

定義

傳回具有指定控制代碼和指派給樹狀檢視控制項的樹狀節點。

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,包含樹狀節點。

handle
IntPtr

nativeint

樹狀節點的控制代碼。

傳回

TreeNode

TreeNode,表示樹狀節點,它被指派給具有指定控制代碼的指定 TreeView 控制項。

範例

下列程式碼範例會取得已折迭的 , TreeNode 並使用其 屬性建立它的 Handle 複本。 原始 TreeNode 專案會從 TreeNodeCollection 中移除,並將複本新增至集合。 此範例會要求您具有 Form TreeView 控制項的 。 控制項 TreeView 應該有兩個以上的根節點,每個節點至少有一個子節點。

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通知。 如果您覆寫 WndProcTreeView 方法來提供自訂繪圖以回應此通知,您應該一律先檢查這個方法 null 的傳回值,再嘗試存取節點。

適用於

另請參閱