Control.DoubleClick Evento

Definição

Ocorre quando o controlo é duplegado.

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

Tipo de Evento

Exemplos

O seguinte exemplo de código usa o DoubleClick evento de a ListBox para carregar ficheiros de texto listados em ListBox um TextBox controlo.

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

Observações

Um duplo clique é determinado pelas definições do rato do sistema operativo do utilizador. O utilizador pode definir o tempo entre cliques de um botão do rato que deve ser considerado um duplo clique em vez de dois cliques. O Click evento é ativado sempre que um controlo é clicado duas vezes. Por exemplo, se tiver manipuladores de eventos para os Click eventos e DoubleClick de um Form, os Click eventos e DoubleClick são levantados quando o formulário é clicado duas vezes e ambos os métodos são chamados. Se um controlo for clicado duas vezes e esse controlo não suportar o DoubleClick evento, o Click evento pode ser levantado duas vezes.

Deve definir os StandardDoubleClick valores e StandardClick de ControlStyles para true que este evento seja elevado. Estes valores podem já estar definidos para true se estiver a herdar de controlos de Windows Forms existentes.

Note

Os seguintes eventos não são levantados para a TabControl classe a menos que haja pelo menos um TabPage na TabControl.TabPages coleção: Click, DoubleClick, MouseDown, MouseUp, MouseHover, MouseEnter, , e MouseLeaveMouseMove. Se houver pelo menos um TabPage na coleção, e o utilizador interagir com o cabeçalho do controlo tab (onde aparecem os TabPage nomes), o TabControl evento apropriado é gerado. No entanto, se a interação do utilizador estiver dentro da área do cliente da página de separador, o TabPage evento apropriado é gerado.

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

Notas para Herdeiros

Herdar de um controlo Windows Forms padrão e alterar os valores StandardClick ou StandardDoubleClick de ControlStyles para true pode causar comportamentos inesperados ou não ter qualquer efeito se o controlo não suportar os eventos Click ou DoubleClick.

A tabela seguinte lista Windows Forms controlos e qual o evento (Click ou DoubleClick) é levantado em resposta à ação do rato especificada.

Controlo Clique Esquerdo do Rato Clique duplo do rato esquerdo Clique Direito do Rato Duplo clique direito do rato Clique do Meio do Rato Clique Duplo do Rato do Meio XButton1 Clique do Rato Rato XButton1 Double-Click XButton2 Clique do Rato Rato XButton2 Double-Click
MonthCalendar,

DateTimePicker,

RichTextBox,

HScrollBar,

VScrollBar

nenhuma

nenhum nenhum nenhum nenhum nenhum nenhum nenhum nenhum nenhum
Button,

CheckBox,

RadioButton

Clique

Clique, Clique nenhum nenhum nenhum nenhum nenhum nenhum nenhum nenhum
ListBox,

CheckedListBox,

ComboBox

Clique

Clique, Duplo Clique nenhum nenhum nenhum nenhum nenhum nenhum nenhum nenhum
TextBox,

DomainUpDown,

NumericUpDown

Clique

Clique, Duplo Clique nenhum nenhum nenhum nenhum nenhum nenhum nenhum nenhum
* TreeView,

* ListView

Clique

Clique, Duplo Clique Clique em Clique, Duplo Clique nenhum nenhum nenhum nenhum nenhum nenhum
ProgressBar,

TrackBar

Clique

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

DataGrid,

Label,

LinkLabel,

Panel,

GroupBox,

PictureBox,

Splitter,

StatusBar,

ToolBar,

TabPage,

** TabControl

Clique

Clique, Duplo Clique Clique em Clique, Duplo Clique Clique em Clique, Duplo Clique Clique em Clique, Duplo Clique Clique em Clique, Duplo Clique

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

** Deve TabControl ter pelo menos um TabPage na sua TabPages coleção.

Aplica-se a

Ver também