Control.DoubleClick Evento

Definición

Se produce cuando se hace doble clic en el control.Occurs when the control is double-clicked.

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

Ejemplos

En el ejemplo de código siguiente se usa el evento DoubleClick de un ListBox para cargar los archivos de texto incluidos en el ListBox en un control TextBox.The following code example uses the DoubleClick event of a ListBox to load text files listed in the ListBox into a TextBox control.

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

Comentarios

La configuración del mouse del sistema operativo del usuario determina el doble clic.A double-click is determined by the mouse settings of the user's operating system. El usuario puede establecer el tiempo entre los clics de un botón del mouse que debe considerarse como un doble clic y no como dos clics.The user can set the time between clicks of a mouse button that should be considered a double-click rather than two clicks. El evento Click se genera cada vez que se hace doble clic en un control.The Click event is raised every time a control is double-clicked. Por ejemplo, si tiene controladores de eventos para los eventos Click y DoubleClick de un Form, se generan los eventos Click y DoubleClick cuando se hace doble clic en el formulario y se llama a ambos métodos.For example, if you have event handlers for the Click and DoubleClick events of a Form, the Click and DoubleClick events are raised when the form is double-clicked and both methods are called. Si se hace doble clic en un control y dicho control no admite el evento DoubleClick, el evento Click podría generarse dos veces.If a control is double-clicked and that control does not support the DoubleClick event, the Click event might be raised twice.

Debe establecer los valores StandardDoubleClick y StandardClick de ControlStyles en true para que se genere este evento.You must set the StandardDoubleClick and StandardClick values of ControlStyles to true for this event to be raised. Es posible que estos valores ya estén establecidos en true si hereda de los controles de Windows Forms existentes.These values might already be set to true if you are inheriting from existing Windows Forms controls.

Nota

Los eventos siguientes no se generan para la clase TabControl a menos que haya al menos un TabPage en la colección TabControl.TabPages: Click, DoubleClick, MouseDown, MouseUp, MouseHover, MouseEnter, MouseLeave y 0.The following events are not raised for the TabControl class unless there is at least one TabPage in the TabControl.TabPages collection: Click, DoubleClick, MouseDown, MouseUp, MouseHover, MouseEnter, MouseLeave and MouseMove. Si hay al menos un TabPage en la colección y el usuario interactúa con el encabezado del control de pestaña (donde aparecen los nombres de TabPage), el TabControl genera el evento adecuado.If there is at least one TabPage in the collection, and the user interacts with the tab control's header (where the TabPage names appear), the TabControl raises the appropriate event. Sin embargo, si la interacción con el usuario se encuentra en el área cliente de la página de ficha, el TabPage genera el evento adecuado.However, if the user interaction is within the client area of the tab page, the TabPage raises the appropriate event.

Para obtener más información sobre el manejo de eventos, consulte controlar y provocar eventos.For more information about handling events, see Handling and Raising Events.

Notas a los desarrolladores de herederos

Heredar de un control de Windows Forms estándar y cambiar los valores StandardClick o StandardDoubleClick de ControlStyles a true puede producir un comportamiento inesperado o no tener ningún efecto si el control no admite los eventos Click o DoubleClick.Inheriting from a standard Windows Forms control and changing the StandardClick or StandardDoubleClick values of ControlStyles to true can cause unexpected behavior or have no effect at all if the control does not support the Click or DoubleClick events.

En la tabla siguiente se enumeran Windows Forms controles y qué evento (Click o DoubleClick) se produce como respuesta a la acción del mouse especificada.The following table lists Windows Forms controls and which event (Click or DoubleClick) is raised in response to the mouse action specified.

ControlControl Clic con el botón primarioLeft Mouse Click Doble clic con el botón primarioLeft Mouse Double Click Clic con el botón secundario del mouseRight Mouse Click Doble clic con el botón secundario del mouseRight Mouse Double Click Clic con el botón central del mouseMiddle Mouse Click Doble clic con el botón centralMiddle Mouse Double Click XButton1 clic del mouseXButton1 Mouse Click Doble clic con el mouse de XButton1XButton1 Mouse Double-Click XButton2 clic del mouseXButton2 Mouse Click Doble clic con el mouse de XButton2XButton2 Mouse Double-Click
MonthCalendar,MonthCalendar, DateTimePicker,DateTimePicker, RichTextBox,RichTextBox, HScrollBar,HScrollBar, VScrollBar ningunanone ningunanone ningunanone ningunanone ningunanone ningunanone ningunanone ningunanone ningunanone ningunanone
Button,Button, CheckBox,CheckBox, RadioButton Haga clicClick Haga clic enClick, Click ningunanone ningunanone ningunanone ningunanone ningunanone ningunanone ningunanone ningunanone
ListBox,ListBox, CheckedListBox,CheckedListBox, ComboBox Haga clicClick Haga clic en, DoubleClickClick, DoubleClick ningunanone ningunanone ningunanone ningunanone ningunanone ningunanone ningunanone ningunanone
TextBox,TextBox, DomainUpDown,DomainUpDown, NumericUpDown Haga clicClick Haga clic en, DoubleClickClick, DoubleClick ningunanone ningunanone ningunanone ningunanone ningunanone ningunanone ningunanone ningunanone
\* TreeView,\* TreeView, \* ListView\* ListView Haga clicClick Haga clic en, DoubleClickClick, DoubleClick Haga clicClick Haga clic en, DoubleClickClick, DoubleClick ningunanone ningunanone ningunanone ningunanone ningunanone ningunanone
ProgressBar,ProgressBar, TrackBar Haga clicClick Haga clic enClick, Click Haga clicClick Haga clic enClick, Click Haga clicClick Haga clic enClick, Click Haga clicClick Haga clic enClick, Click Haga clicClick Haga clic enClick, Click
Form,Form, DataGrid,DataGrid, Label,Label, LinkLabel,LinkLabel, Panel,Panel, GroupBox,GroupBox, PictureBox,PictureBox, Splitter,Splitter, StatusBar,StatusBar, ToolBar,ToolBar, TabPage,TabPage, ** TabControl Haga clicClick Haga clic en, DoubleClickClick, DoubleClick Haga clicClick Haga clic en, DoubleClickClick, DoubleClick Haga clicClick Haga clic en, DoubleClickClick, DoubleClick Haga clicClick Haga clic en, DoubleClickClick, DoubleClick Haga clicClick Haga clic en, DoubleClickClick, DoubleClick

* el puntero del mouse debe estar sobre un objeto secundario (TreeNode o ListViewItem).* The mouse pointer must be over a child object (TreeNode or ListViewItem).

* * El TabControl debe tener al menos un TabPage en su colección TabPages.** The TabControl must have at least one TabPage in its TabPages collection.

Se aplica a

Consulte también: