Control.DoubleClick Evento

Definición

Se produce cuando se hace doble clic en el control.

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

Tipo de evento

Ejemplos

En el ejemplo de código siguiente se usa el DoubleClick evento de para ListBox cargar archivos de texto enumerados en un ListBoxTextBox 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

Un doble clic viene determinado por la configuración del mouse del sistema operativo del usuario. El usuario puede establecer el tiempo entre clics de un botón del mouse que se debe considerar un doble clic en lugar de dos clics. El Click evento se genera cada vez que se hace doble clic en un control. Por ejemplo, si tiene controladores de eventos para los Click eventos y DoubleClick de , Formlos Click eventos y DoubleClick se generan cuando se hace doble clic en el formulario y se llama a ambos métodos. Si se hace doble clic en un control y ese control no admite el DoubleClick evento, es posible que el Click evento se genere dos veces.

Debe establecer los StandardDoubleClick valores y StandardClick de ControlStylestrue en para que se genere este evento. Es posible que estos valores ya estén establecidos en true si hereda de los controles de Windows Forms existentes.

Note

Los siguientes eventos no se generan para la TabControl clase a menos que haya al menos uno TabPage en la TabControl.TabPages colección: Click, , DoubleClickMouseDown, , MouseUpMouseHover, y MouseEnterMouseLeaveMouseMove. Si hay al menos una TabPage en la colección y el usuario interactúa con el encabezado del control de pestaña (donde aparecen los TabPage nombres), TabControl genera el evento adecuado. Sin embargo, si la interacción del usuario está dentro del área cliente de la página de pestañas, TabPage genera el evento adecuado.

Para obtener más información sobre el manejo de eventos, consulte controlar y provocar eventos.

Notas a los desarrolladores de herederos

Heredar de un control Windows Forms estándar y cambiar el StandardClick o StandardDoubleClick valores de ControlStyles a true puede provocar un comportamiento inesperado o no tener ningún efecto si el control no admite los eventos Click o DoubleClick.

En la tabla siguiente se enumeran los controles Windows Forms y qué evento (Click o DoubleClick) se genera en respuesta a la acción del mouse especificada.

Control Clic con el mouse izquierdo Clic doble del mouse izquierdo Haga clic con el botón derecho del mouse Clic doble del mouse derecho Clic central del mouse Clic doble del mouse central Clic del mouse XButton1 Double-Click del mouse XButton1 Clic del mouse XButton2 Double-Click del mouse XButton2
MonthCalendar,

DateTimePicker,

RichTextBox,

HScrollBar,

VScrollBar

Ninguno

ninguno ninguno ninguno ninguno ninguno ninguno ninguno ninguno ninguno
Button,

CheckBox,

RadioButton

Haga clic en

Haga clic, haga clic en ninguno ninguno ninguno ninguno ninguno ninguno ninguno ninguno
ListBox,

CheckedListBox,

ComboBox

Haga clic en

Haga clic en DoubleClick. ninguno ninguno ninguno ninguno ninguno ninguno ninguno ninguno
TextBox,

DomainUpDown,

NumericUpDown

Haga clic en

Haga clic en DoubleClick. ninguno ninguno ninguno ninguno ninguno ninguno ninguno ninguno
* TreeView,

* ListView

Haga clic en

Haga clic en DoubleClick. Clic Haga clic en DoubleClick. ninguno ninguno ninguno ninguno ninguno ninguno
ProgressBar,

TrackBar

Haga clic en

Haga clic, haga clic en Clic Haga clic, haga clic en Clic Haga clic, haga clic en Clic Haga clic, haga clic en Clic Haga clic, haga clic en
Form,

DataGrid,

Label,

LinkLabel,

Panel,

GroupBox,

PictureBox,

Splitter,

StatusBar,

ToolBar,

TabPage,

** TabControl

Haga clic en

Haga clic en DoubleClick. Clic Haga clic en DoubleClick. Clic Haga clic en DoubleClick. Clic Haga clic en DoubleClick. Clic Haga clic en DoubleClick.

* El puntero del mouse debe estar sobre un objeto secundario (TreeNode o ListViewItem).

** El TabControl debe tener al menos uno TabPage en su TabPages colección.

Se aplica a

Consulte también