共用方式為


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 。 若要執行此範例,請將程式碼貼到包含 TreeView 具名 treeView1 的 Windows Form 中。 treeView1填入範例執行所在 c:\ 系統目錄中的檔案名,並將 的 事件 treeView1 與此 treeView1_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

備註

當使用者使用滑鼠按兩下樹狀節點的任何部分時,就會發生這個事件,包括加號 (+) 或減號 (-) ,指出節點是否已折迭或展開。

如需處理事件的詳細資訊,請參閱 處理和引發事件

適用於

另請參閱