Control.DoubleClick Evento

Definição

Ocorre quando um usuário clica duas vezes no controle.

public:
 event EventHandler ^ DoubleClick;
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 seguir usa o DoubleClick evento de um ListBox para carregar arquivos de texto listados no em ListBox 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

O 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 de um Form, os Click eventos e DoubleClick 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 der suporte ao DoubleClick evento, o Click evento poderá ser gerado duas vezes.

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

Observação

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, MouseLeaveMouseEntere MouseMove. Se houver pelo menos um TabPage na coleção e o usuário interagir com o cabeçalho do controle guia (em que os TabPage nomes aparecem), o aciona o TabControl evento apropriado. No entanto, se a interação do usuário estiver dentro da área do cliente da página da guia, o TabPage gerará o evento apropriado.

Para obter mais informações sobre como lidar com eventos, consulte Manipulando e levantando eventos.

Notas aos Herdeiros

Herdar de um controle de Windows Forms padrão e alterar os StandardClick valores ou StandardDoubleClick de ControlStyles para true poderá causar um comportamento inesperado ou não ter nenhum efeito se o controle não der suporte aos Click eventos 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 com o botão esquerdo do mouse Clique duplo do mouse à esquerda Clique com o botão direito do mouse Clique duplo com o botão direito do mouse Clique do Meio do Mouse Clique duplo do mouse do meio Clique do Mouse XButton1 Double-Click de mouse XButton1 Clique do Mouse XButton2 Double-Click de mouse XButton2
MonthCalendar,

DateTimePicker,

RichTextBox,

HScrollBar,

VScrollBar

nenhum nenhum nenhum nenhum nenhum nenhum nenhum nenhum nenhum nenhum
Button,

CheckBox,

RadioButton

Clique em Clique em, clique em nenhum nenhum nenhum nenhum nenhum nenhum nenhum nenhum
ListBox,

CheckedListBox,

ComboBox

Clique em Clique em DoubleClick nenhum nenhum nenhum nenhum nenhum nenhum nenhum nenhum
TextBox,

DomainUpDown,

NumericUpDown

Clique em Clique em DoubleClick nenhum nenhum nenhum nenhum nenhum nenhum nenhum nenhum
* TreeView,

* ListView

Clique em Clique em DoubleClick Clique em Clique em DoubleClick nenhum nenhum nenhum nenhum nenhum nenhum
ProgressBar,

TrackBar

Clique em Clique em, clique em Clique em Clique em, clique em Clique em Clique em, clique em Clique em Clique em, clique em Clique em Clique em, 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