Control.DoubleClick Control.DoubleClick Control.DoubleClick Control.DoubleClick Event

Definição

Ocorre quando um usuário clica duas vezes no controle.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 

Exemplos

O exemplo de código a seguir DoubleClick usa o evento ListBox de um para carregar arquivos de ListBox texto listados no TextBox em um controle.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

Comentários

O clique duplo é determinado pelas configurações do mouse do sistema operacional do usuário.A double-click is determined by the mouse settings of the user's operating system. O usuário pode definir o tempo entre cliques de um botão do mouse que deve ser considerado um clique duplo em vez de dois cliques.The user can set the time between clicks of a mouse button that should be considered a double-click rather than two clicks. O Click evento é gerado toda vez que um controle é clicado duas vezes.The Click event is raised every time a control is double-clicked. Por exemplo, se você tiver manipuladores de eventos para Click os DoubleClick eventos e de Forma, Click os DoubleClick eventos e serão gerados quando o formulário for clicado duas vezes e ambos os métodos forem chamados.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. Se um controle for clicado duas vezes e esse controle não oferecer suporte DoubleClick ao evento, Click o evento poderá ser gerado duas vezes.If a control is double-clicked and that control does not support the DoubleClick event, the Click event might be raised twice.

Você deve definir os StandardDoubleClick valores StandardClick e de ControlStyles para true para que esse evento seja gerado.You must set the StandardDoubleClick and StandardClick values of ControlStyles to true for this event to be raised. Esses valores podem já estar definidos como true se você estiver herdando de controles de Windows Forms existentes.These values might already be set to true if you are inheriting from existing Windows Forms controls.

Observação

Os eventos a seguir não são gerados para TabControl a classe, a menos que haja TabPage pelo menos TabControl.TabPages um na Clickcoleção DoubleClick: MouseDown, MouseUp MouseHover MouseEnter,,,,, MouseLeave e .MouseMoveThe 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. Se houver pelo menos um TabPage na coleção e o usuário interagir com o cabeçalho do controle guia (onde os TabPage nomes são exibidos), o TabControl gerará o evento apropriado.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. No entanto, se a interação do usuário estiver dentro da área do cliente da página TabPage da guia, o gerará o evento apropriado.However, if the user interaction is within the client area of the tab page, the TabPage raises the appropriate event.

Para obter mais informações sobre como manipular eventos, consulte manipulando e gerando eventos.For more information about handling events, see Handling and Raising Events.

Notas aos Herdeiros

Herdar de um controle de Windows Forms padrão e alterar StandardClick os StandardDoubleClick valores ou ControlStyles de true para pode causar Click um comportamento inesperado ou não ter nenhum efeito se o controle não oferecer suporte ao ou DoubleClickaoeventos.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.

A tabela a seguir lista Windows Forms controles e qual eventoClick ( DoubleClickou) é gerado em resposta à ação do mouse especificada.The following table lists Windows Forms controls and which event (Click or DoubleClick) is raised in response to the mouse action specified.

ControleControl Clique com o botão esquerdo do mouseLeft Mouse Click Clique duas vezes no botão esquerdo do mouseLeft Mouse Double Click Clique com o botão direito do mouseRight Mouse Click Clique duas vezes com o botão direito do mouseRight Mouse Double Click Clique no meio do mouseMiddle Mouse Click Clique duas vezes no meio do mouseMiddle Mouse Double Click Clique com o mouse XButton1XButton1 Mouse Click Clique duas vezes com o mouse XButton1XButton1 Mouse Double-Click Clique com o mouse XButton2XButton2 Mouse Click Clique duas vezes com o mouse XButton2XButton2 Mouse Double-Click
MonthCalendar,MonthCalendar, DateTimePicker,DateTimePicker, RichTextBox,RichTextBox, HScrollBar,HScrollBar, VScrollBar nenhumnone nenhumnone nenhumnone nenhumnone nenhumnone nenhumnone nenhumnone nenhumnone nenhumnone nenhumnone
Button,Button, CheckBox,CheckBox, RadioButton Clique emClick Clique em, clique emClick, Click nenhumnone nenhumnone nenhumnone nenhumnone nenhumnone nenhumnone nenhumnone nenhumnone
ListBox,ListBox, CheckedListBox,CheckedListBox, ComboBox Clique emClick Clique em, DoubleClickClick, DoubleClick nenhumnone nenhumnone nenhumnone nenhumnone nenhumnone nenhumnone nenhumnone nenhumnone
TextBox,TextBox, DomainUpDown,DomainUpDown, NumericUpDown Clique emClick Clique em, DoubleClickClick, DoubleClick nenhumnone nenhumnone nenhumnone nenhumnone nenhumnone nenhumnone nenhumnone nenhumnone
\* TreeView,\* TreeView, \* ListView\* ListView Clique emClick Clique em, DoubleClickClick, DoubleClick Clique emClick Clique em, DoubleClickClick, DoubleClick nenhumnone nenhumnone nenhumnone nenhumnone nenhumnone nenhumnone
ProgressBar,ProgressBar, TrackBar Clique emClick Clique em, clique emClick, Click Clique emClick Clique em, clique emClick, Click Clique emClick Clique em, clique emClick, Click Clique emClick Clique em, clique emClick, Click Clique emClick Clique em, clique emClick, Click
Form,Form, DataGrid,DataGrid, Label,Label, LinkLabel,LinkLabel, Panel,Panel, GroupBox,GroupBox, PictureBox,PictureBox, Splitter,Splitter, StatusBar,StatusBar, ToolBar,ToolBar, TabPage,TabPage, ** TabControl Clique emClick Clique em, DoubleClickClick, DoubleClick Clique emClick Clique em, DoubleClickClick, DoubleClick Clique emClick Clique em, DoubleClickClick, DoubleClick Clique emClick Clique em, DoubleClickClick, DoubleClick Clique emClick Clique em, DoubleClickClick, DoubleClick

*O ponteiro do mouse deve ser sobre um objeto filhoTreeNode ( ListViewItemou).* The mouse pointer must be over a child object (TreeNode or ListViewItem).

* * O TabControl deve ter pelo menos um TabPage em sua TabPages coleção.** The TabControl must have at least one TabPage in its TabPages collection.

Aplica-se a

Veja também