TreeView.NodeMouseDoubleClick 事件

定义

当用户使用鼠标双击 TreeNode 时发生。

public:
 event System::Windows::Forms::TreeNodeMouseClickEventHandler ^ NodeMouseDoubleClick;
public event System.Windows.Forms.TreeNodeMouseClickEventHandler NodeMouseDoubleClick;
public event System.Windows.Forms.TreeNodeMouseClickEventHandler? NodeMouseDoubleClick;
member this.NodeMouseDoubleClick : System.Windows.Forms.TreeNodeMouseClickEventHandler 
Public Custom Event NodeMouseDoubleClick As TreeNodeMouseClickEventHandler 

事件类型

示例

下面的代码示例演示如何处理 NodeMouseDoubleClick 事件以及如何使用 TreeNodeMouseClickEventArgs。 若要运行此示例,请将代码粘贴到包含名为 treeView1TreeView Windows 窗体中。 treeView1使用运行示例的系统目录中的文件c:\的名称进行填充,并将 的事件treeView1treeView1_NodeMouseDoubleClick此示例中的 方法相关联NodeMouseDoubleClick。 此示例要求用户在运行此示例的计算机上具有管理员权限。

    // If a node is double-clicked, open the file indicated by the TreeNode.
private:
    void InitialTreeView_NodeMouseDoubleClick(Object^ sender,
        TreeNodeMouseClickEventArgs^ e)
    {
        try
        {
            // Look for a file extension.
            if (e->Node->Text->Contains("."))
            {
                System::Diagnostics::Process::Start("c:\\" + e->Node->Text);
            }
        }
        // If the file is not found, handle the exception and inform the user.
        catch (System::ComponentModel::Win32Exception^)
        {
            MessageBox::Show("File not found.");
        }
    }
// If a node is double-clicked, open the file indicated by the TreeNode.
void treeView1_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e)
{
    try
    {
        // Look for a file extension.
        if (e.Node.Text.Contains("."))
            System.Diagnostics.Process.Start(@"c:\" + e.Node.Text);
    }
        // If the file is not found, handle the exception and inform the user.
    catch (System.ComponentModel.Win32Exception)
    {
        MessageBox.Show("File not found.");
    }
}
' If a node is double-clicked, open the file indicated by the TreeNode.
Sub treeView1_NodeMouseDoubleClick(ByVal sender As Object, _
    ByVal e As TreeNodeMouseClickEventArgs) _
    Handles treeView1.NodeMouseDoubleClick

    Try
        ' Look for a file extension, and open the file.
        If e.Node.Text.Contains(".") Then
            System.Diagnostics.Process.Start("c:\" + e.Node.Text)
        End If
        ' If the file is not found, handle the exception and inform the user.
    Catch
        MessageBox.Show("File not found.")
    End Try

End Sub

注解

当用户使用鼠标双击树节点的任何部分(包括加号 (+) 或减号 ( ) 指示节点是折叠还是展开)时,会发生此事件。

有关处理事件的详细信息,请参阅 处理和引发事件

适用于

另请参阅