• 通过检查包含与事件相关的数据的 TreeViewEventArgs 类来确定单击了哪个节点。

    Private Sub TreeView1_AfterSelect(ByVal sender As System.Object, _  
    ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterSelect  
       ' Determine by checking the Node property of the TreeViewEventArgs.  
       MessageBox.Show(e.Node.Text)  
    End Sub  
    
    protected void treeView1_AfterSelect (object sender,
    System.Windows.Forms.TreeViewEventArgs e)  
       // Determine by checking the Text property.  
       MessageBox.Show(e.Node.Text);  
    
    private:  
       void treeView1_AfterSelect(System::Object ^  sender,  
          System::Windows::Forms::TreeViewEventArgs ^  e)  
          // Determine by checking the Text property.  
          MessageBox::Show(e->Node->Text);  
    

    或者,可以使用 MouseDownMouseUp 事件的 MouseEventArgs 来获取单击时的 PointXY 坐标值。 然后,使用 TreeView 控件的 GetNodeAt 方法来确定单击了哪个节点。

  • TreeView 控件
  •