TreeView.NodeMouseDoubleClick Evento

Definizione

Si verifica quando l'utente fa doppio clic su un oggetto 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 

Tipo evento

Esempio

Nell'esempio di codice seguente viene illustrato come gestire l'evento NodeMouseDoubleClick e come usare .TreeNodeMouseClickEventArgs Per eseguire questo esempio, incollare il codice in un Windows Form contenente un TreeView oggetto denominato treeView1. treeView1 Popolare con i nomi dei file che si trovano nella c:\ directory del sistema in cui è in esecuzione l'esempio e associare l'evento NodeMouseDoubleClick di treeView1 al treeView1_NodeMouseDoubleClick metodo in questo esempio. Questo esempio richiede che l'utente disponga dei privilegi di amministratore nel computer che esegue l'esempio.

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

Commenti

Questo evento si verifica quando l'utente fa doppio clic su qualsiasi parte di un nodo della struttura ad albero con il mouse, incluso il segno più (+) o il segno meno (-) che indica se il nodo è compresso o espanso.

Per ulteriori informazioni sulla gestione degli eventi, consultare gestione e generazione di eventi.

Si applica a

Vedi anche