Control.DoubleClick Gebeurtenis

Definitie

Treedt op wanneer op het besturingselement wordt dubbelklikken.

public:
 event EventHandler ^ DoubleClick;
public event EventHandler DoubleClick;
public event EventHandler? DoubleClick;
member this.DoubleClick : EventHandler 
Public Custom Event DoubleClick As EventHandler 

Gebeurtenistype

Voorbeelden

In het volgende codevoorbeeld wordt de DoubleClick gebeurtenis van een ListBox bestand gebruikt om tekstbestanden in een ListBoxTextBox besturingselement te laden.

   // This example uses the DoubleClick event of a ListBox to load text files
   // listed in the ListBox into a TextBox control. This example
   // assumes that the ListBox, named listBox1, contains a list of valid file
   // names with path and that this event handler method
   // is connected to the DoublClick event of a ListBox control named listBox1.
   // This example requires code access permission to access files.
private:
   void listBox1_DoubleClick( Object^ /*sender*/, System::EventArgs^ /*e*/ )
   {
      // Get the name of the file to open from the ListBox.
      String^ file = listBox1->SelectedItem->ToString();
      try
      {
         // Determine if the file exists before loading.
         if ( System::IO::File::Exists( file ) )
         {
            
            // Open the file and use a TextReader to read the contents into the TextBox.
            System::IO::FileInfo^ myFile = gcnew System::IO::FileInfo( listBox1->SelectedItem->ToString() );
            System::IO::TextReader^ myData = myFile->OpenText();
            ;
            textBox1->Text = myData->ReadToEnd();
            myData->Close();
         }
      }
      // Exception is thrown by the OpenText method of the FileInfo class.
      catch ( System::IO::FileNotFoundException^ ) 
      {
         MessageBox::Show( "The file you specified does not exist." );
      }
      // Exception is thrown by the ReadToEnd method of the TextReader class.
      catch ( System::IO::IOException^ ) 
      {
         MessageBox::Show( "There was a problem loading the file into the TextBox. Ensure that the file is a valid text file." );
      }
   }
// This example uses the DoubleClick event of a ListBox to load text files
// listed in the ListBox into a TextBox control. This example
// assumes that the ListBox, named listBox1, contains a list of valid file
// names with path and that this event handler method
// is connected to the DoublClick event of a ListBox control named listBox1.
// This example requires code access permission to access files.
private void listBox1_DoubleClick(object sender, System.EventArgs e)
{
    // Get the name of the file to open from the ListBox.
    String file = listBox1.SelectedItem.ToString();

    try
    {
        // Determine if the file exists before loading.
        if (System.IO.File.Exists(file))
        {
            // Open the file and use a TextReader to read the contents into the TextBox.
            System.IO.FileInfo myFile = new System.IO.FileInfo(listBox1.SelectedItem.ToString());
            System.IO.TextReader myData = myFile.OpenText();;

            textBox1.Text = myData.ReadToEnd();
            myData.Close();
        }
    }
        // Exception is thrown by the OpenText method of the FileInfo class.
    catch(System.IO.FileNotFoundException)
    {
        MessageBox.Show("The file you specified does not exist.");
    }
        // Exception is thrown by the ReadToEnd method of the TextReader class.
    catch(System.IO.IOException)
    {
        MessageBox.Show("There was a problem loading the file into the TextBox. Ensure that the file is a valid text file.");
    }
}
' This example uses the DoubleClick event of a ListBox to load text files  
' listed in the ListBox into a TextBox control. This example
' assumes that the ListBox, named listBox1, contains a list of valid file 
' names with path and that this event handler method
' is connected to the DoublClick event of a ListBox control named listBox1.
' This example requires code access permission to access files.
Private Sub listBox1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles listBox1.DoubleClick
    ' Get the name of the file to open from the ListBox.
    Dim file As [String] = listBox1.SelectedItem.ToString()

    Try
        ' Determine if the file exists before loading.
        If System.IO.File.Exists(file) Then
            ' Open the file and use a TextReader to read the contents into the TextBox.
            Dim myFile As New System.IO.FileInfo(listBox1.SelectedItem.ToString())
            Dim myData As System.IO.TextReader = myFile.OpenText()

            textBox1.Text = myData.ReadToEnd()
            myData.Close()
        End If
        ' Exception is thrown by the OpenText method of the FileInfo class.
    Catch
        MessageBox.Show("The file you specified does not exist.")
        ' Exception is thrown by the ReadToEnd method of the TextReader class.
    Catch
     MessageBox.Show("There was a problem loading the file into the TextBox. Ensure that the file is a valid text file.")
    End Try
End Sub

Opmerkingen

Een dubbelklik wordt bepaald door de muisinstellingen van het besturingssysteem van de gebruiker. De gebruiker kan de tijd instellen tussen klikken van een muisknop die moet worden beschouwd als een dubbelklik in plaats van twee klikken. De Click gebeurtenis wordt gegenereerd telkens wanneer er op een besturingselement wordt gedubbelklikt. Als u bijvoorbeeld gebeurtenis-handlers hebt voor de Click en DoubleClick gebeurtenissen van een Form, worden de Click en DoubleClick gebeurtenissen gegenereerd wanneer op het formulier wordt gedubbelklikt en beide methoden worden aangeroepen. Als er op een besturingselement wordt gedubbelklikt en dat besturingselement de DoubleClick gebeurtenis niet ondersteunt, kan de Click gebeurtenis twee keer worden gegenereerd.

U moet de en StandardDoubleClick waarden StandardClick instellen voor ControlStylestrue deze gebeurtenis die moet worden gegenereerd. Deze waarden zijn mogelijk al ingesteld op true als u overname van bestaande Windows Forms besturingselementen.

Note

De volgende gebeurtenissen worden niet voor de TabControl klasse gegenereerd, tenzij er ten minste één TabPage in de TabControl.TabPages verzameling staat: Click, , DoubleClickMouseDown, MouseUp, , MouseHoveren MouseEnterMouseLeaveMouseMove. Als er ten minste één TabPage in de verzameling staat en de gebruiker communiceert met de koptekst van het tabblad besturingselement (waar de TabPage namen worden weergegeven), wordt de TabControl juiste gebeurtenis gegenereerd. Als de interactie van de gebruiker zich echter binnen het clientgebied van de tabbladpagina bevindt, wordt de TabPage juiste gebeurtenis gegenereerd.

Zie Gebeurtenissen verwerken en genereren voor meer informatie over het afhandelen van gebeurtenissen.

Notities voor overnemers

Overnemen van een standaard Windows Forms besturingselement en het wijzigen van de StandardClick of StandardDoubleClick waarden van ControlStyles in true kan onverwacht gedrag veroorzaken of helemaal geen effect hebben als het besturingselement de Click of DoubleClick gebeurtenissen niet ondersteunt.

De volgende tabel bevat Windows Forms besturingselementen en welke gebeurtenis (Click of DoubleClick) wordt gegenereerd als reactie op de opgegeven muisactie.

Controle Klik met de linkermuisknop Dubbelklik met linkermuis Klik met de rechtermuisknop Dubbelklik met de rechtermuisknop Middelste muisklik Middelste muis dubbelklikken XButton1-muisklik XButton1-muis Double-Click XButton2-muisklik XButton2-muis Double-Click
MonthCalendar,

DateTimePicker,

RichTextBox,

HScrollBar,

VScrollBar

none

geen geen geen geen geen geen geen geen geen
Button,

CheckBox,

RadioButton

Klikt u op

Klik, klik op geen geen geen geen geen geen geen geen
ListBox,

CheckedListBox,

ComboBox

Klikt u op

Klik, DoubleClick geen geen geen geen geen geen geen geen
TextBox,

DomainUpDown,

NumericUpDown

Klikt u op

Klik, DoubleClick geen geen geen geen geen geen geen geen
* TreeView,

* ListView

Klikt u op

Klik, DoubleClick Klik op Klik, DoubleClick geen geen geen geen geen geen
ProgressBar,

TrackBar

Klikt u op

Klik, klik op Klik op Klik, klik op Klik op Klik, klik op Klik op Klik, klik op Klik op Klik, klik op
Form,

DataGrid,

Label,

LinkLabel,

Panel,

GroupBox,

PictureBox,

Splitter,

StatusBar,

ToolBar,

TabPage,

** TabControl

Klikt u op

Klik, DoubleClick Klik op Klik, DoubleClick Klik op Klik, DoubleClick Klik op Klik, DoubleClick Klik op Klik, DoubleClick

* De muis aanwijzer moet boven een onderliggend object (TreeNode of ListViewItem) staan.

** De TabControl verzameling moet ten minste één TabPage bevatten TabPages .

Van toepassing op

Zie ook