Share via


TreeView.NodeMouseDoubleClick Kejadian

Definisi

Terjadi ketika pengguna mengklik dua kali dengan TreeNode mouse.

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 

Jenis Acara

Contoh

Contoh kode berikut menunjukkan cara menangani NodeMouseDoubleClick peristiwa dan cara menggunakan TreeNodeMouseClickEventArgs. Untuk menjalankan contoh ini, tempelkan kode ke dalam Formulir Windows yang berisi bernama TreeViewtreeView1. treeView1 Isi dengan nama file yang terletak di c:\ direktori sistem tempat sampel dijalankan, dan kaitkan NodeMouseDoubleClick peristiwa treeView1 dengan treeView1_NodeMouseDoubleClick metode dalam contoh ini. Contoh ini mengharuskan pengguna memiliki hak istimewa administrator pada komputer yang menjalankan contoh.

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

Keterangan

Peristiwa ini terjadi ketika pengguna mengklik dua kali bagian mana pun dari simpul pohon dengan mouse, termasuk tanda plus (+) atau tanda minus (-) yang menunjukkan apakah simpul diciutkan atau diperluas.

Untuk informasi selengkapnya tentang menangani peristiwa, lihat Menangani dan Menaikkan Peristiwa.

Berlaku untuk

Lihat juga