TreeView.NodeMouseDoubleClick TreeView.NodeMouseDoubleClick TreeView.NodeMouseDoubleClick TreeView.NodeMouseDoubleClick Event

定义

当用户使用鼠标双击 TreeNode 时发生。Occurs when the user double-clicks a TreeNode with the mouse.

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使用。The following code example demonstrates how to handle the NodeMouseDoubleClick event and how to use the TreeNodeMouseClickEventArgs. 若要运行此示例, 请将代码粘贴到包含TreeView名为treeView1的的 Windows 窗体中。To run this example, paste the code into a Windows Form that contains a TreeView named treeView1. treeView1运行示例的系统c:\目录中的文件的名称填充, treeView1并将的NodeMouseDoubleClick事件与此示例中的treeView1_NodeMouseDoubleClick方法相关联。Populate treeView1 with the names of files located in the c:\ directory of the system the sample is running on, and associate the NodeMouseDoubleClick event of treeView1 with the treeView1_NodeMouseDoubleClick method in this example. 此示例要求用户在运行该示例的计算机上具有管理员权限。This example requires that the user has administrator privileges on the machine running the example.

    // 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 'treeView1_NodeMouseDoubleClick

注解

当用户使用鼠标双击树节点的任何部分时, 将发生此事件, 包括指示节点是折叠还是展开状态的加号 (+) 或减号 (-)。This event occurs when the user double-clicks any part of a tree node with the mouse, including the plus sign (+) or minus sign (-) that indicates whether the node is collapsed or expanded.

有关处理事件的详细信息, 请参阅处理和引发事件For more information about handling events, see Handling and Raising Events.

适用于

另请参阅