Control.DoubleClick Evento

Definição

Ocorre quando o controle é clicado duas vezes.

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

Tipo de evento

Exemplos

O exemplo de código a ListBox seguir usa o DoubleClick evento de um ListBox para carregar arquivos de texto listados em um TextBox controle.

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

Um clique duplo é determinado pelas configurações do mouse do sistema operacional do usuário. 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. O Click evento é gerado sempre que um controle é clicado duas vezes. Por exemplo, se você tiver manipuladores de eventos para os Click eventos e DoubleClick eventos de umForm, os eventos e DoubleClick os Click eventos serão gerados quando o formulário for clicado duas vezes e ambos os métodos forem chamados. Se um controle for clicado duas vezes e esse controle não oferecer suporte ao DoubleClick evento, o Click evento poderá ser gerado duas vezes.

Você deve definir os valores e StandardClick valores StandardDoubleClick para ControlStylestrue esse evento a ser gerado. Esses valores já poderão ser definidos como true se você estiver herdando de controles Windows Forms existentes.

Note

Os eventos a seguir não são gerados para a classe, TabControl a menos que haja pelo menos um TabPage na TabControl.TabPages coleção: Click, , DoubleClick, MouseDown, MouseUp, , MouseHover, MouseEntere MouseLeaveMouseMove. Se houver pelo menos um TabPage na coleção e o usuário interagir com o cabeçalho do controle de tabulação (em que os TabPage nomes aparecem), o TabControl evento será gerado. No entanto, se a interação do usuário estiver dentro da área do cliente da página de tabulação, ele gerará TabPage o evento apropriado.

Para obter mais informações sobre como manipular eventos, consulte Manipulando e gerando eventos.

Notas aos Herdeiros

Herdar de um controle de Windows Forms padrão e alterar os valores StandardClick ou StandardDoubleClick de ControlStyles para true poderá causar comportamento inesperado ou não ter nenhum efeito se o controle não der suporte aos eventos Click ou DoubleClick.

A tabela a seguir lista Windows Forms controles e qual evento (Click ou DoubleClick) é gerado em resposta à ação do mouse especificada.

Control Clique no mouse à esquerda Clique duplo do mouse à esquerda Clique com o botão direito do mouse Clique duas vezes no mouse com o botão direito do mouse Clique no mouse do meio Clique duplo do mouse do meio Clique no mouse do XButton1 Double-Click do mouse XButton1 Clique no mouse XButton2 Double-Click de mouse XButton2
MonthCalendar,

DateTimePicker,

RichTextBox,

HScrollBar,

VScrollBar

Nenhum

Nenhuma Nenhuma Nenhuma Nenhuma Nenhuma Nenhuma Nenhuma Nenhuma Nenhuma
Button,

CheckBox,

RadioButton

Clique em

Clique, clique em Nenhuma Nenhuma Nenhuma Nenhuma Nenhuma Nenhuma Nenhuma Nenhuma
ListBox,

CheckedListBox,

ComboBox

Clique em

Clique em DoubleClick Nenhuma Nenhuma Nenhuma Nenhuma Nenhuma Nenhuma Nenhuma Nenhuma
TextBox,

DomainUpDown,

NumericUpDown

Clique em

Clique em DoubleClick Nenhuma Nenhuma Nenhuma Nenhuma Nenhuma Nenhuma Nenhuma Nenhuma
* TreeView,

* ListView

Clique em

Clique em DoubleClick Clique em Clique em DoubleClick Nenhuma Nenhuma Nenhuma Nenhuma Nenhuma Nenhuma
ProgressBar,

TrackBar

Clique em

Clique, clique em Clique em Clique, clique em Clique em Clique, clique em Clique em Clique, clique em Clique em Clique, clique em
Form,

DataGrid,

Label,

LinkLabel,

Panel,

GroupBox,

PictureBox,

Splitter,

StatusBar,

ToolBar,

TabPage,

** TabControl

Clique em

Clique em DoubleClick Clique em Clique em DoubleClick Clique em Clique em DoubleClick Clique em Clique em DoubleClick Clique em Clique em DoubleClick

* O ponteiro do mouse deve estar sobre um objeto filho (TreeNode ou ListViewItem).

** O TabControl deve ter pelo menos um TabPage em sua TabPages coleção.

Aplica-se a

Confira também