Control.Click Evento

Definição

Ocorre quando um usuário clica no controle.Occurs when the control is clicked.

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

Exemplos

O exemplo de código a seguir mostra o evento Click em um manipulador de eventos.The following code example shows the Click event in an event handler.

   // This example uses the Parent property and the Find method of Control to set
   // properties on the parent control of a Button and its Form. The example assumes
   // that a Button control named button1 is located within a GroupBox control. The 
   // example also assumes that the Click event of the Button control is connected to
   // the event handler method defined in the example.
private:
   void button1_Click( Object^ /*sender*/, System::EventArgs^ /*e*/ )
   {
      // Get the control the Button control is located in. In this case a GroupBox.
      Control^ control = button1->Parent;
      
      // Set the text and backcolor of the parent control.
      control->Text = "My Groupbox";
      control->BackColor = Color::Blue;
      
      // Get the form that the Button control is contained within.
      Form^ myForm = button1->FindForm();
      
      // Set the text and color of the form containing the Button.
      myForm->Text = "The Form of My Control";
      myForm->BackColor = Color::Red;
   }
// This example uses the Parent property and the Find method of Control to set
// properties on the parent control of a Button and its Form. The example assumes
// that a Button control named button1 is located within a GroupBox control. The 
// example also assumes that the Click event of the Button control is connected to
// the event handler method defined in the example.
private void button1_Click(object sender, System.EventArgs e)
{
   // Get the control the Button control is located in. In this case a GroupBox.
   Control control = button1.Parent;
   // Set the text and backcolor of the parent control.
   control.Text = "My Groupbox";
   control.BackColor = Color.Blue;
   // Get the form that the Button control is contained within.
   Form myForm = button1.FindForm();
   // Set the text and color of the form containing the Button.
   myForm.Text = "The Form of My Control";
   myForm.BackColor = Color.Red;
}
' This example uses the Parent property and the Find method of Control to set
' properties on the parent control of a Button and its Form. The example assumes
' that a Button control named button1 is located within a GroupBox control. The 
' example also assumes that the Click event of the Button control is connected to
' the event handler method defined in the example.
Private Sub button1_Click(sender As Object, e As System.EventArgs) Handles button1.Click
   ' Get the control the Button control is located in. In this case a GroupBox.
   Dim control As Control = button1.Parent
   ' Set the text and backcolor of the parent control.
   control.Text = "My Groupbox"
   control.BackColor = Color.Blue
   ' Get the form that the Button control is contained within.
   Dim myForm As Form = button1.FindForm()
   ' Set the text and color of the form containing the Button.
   myForm.Text = "The Form of My Control"
   myForm.BackColor = Color.Red
End Sub

Comentários

O evento Click passa um EventArgs para seu manipulador de eventos, portanto, ele indica apenas que ocorreu um clique.The Click event passes an EventArgs to its event handler, so it only indicates that a click has occurred. Caso você precise de informações do mouse mais específicas (botão, número de cliques, giro da roda ou local), use o evento MouseClick.If you need more specific mouse information (button, number of clicks, wheel rotation, or location), use the MouseClick event. No entanto, o evento MouseClick não será acionado se o clique for causado pela ação que não seja do mouse, como pressione a tecla ENTER.However, the MouseClick event will not be raised if the click is caused by action other than that of the mouse, such as pressing the ENTER key.

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 evento Click é 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 os eventos Click e DoubleClick de um Form, os eventos Click e DoubleClick 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 ao evento DoubleClick, o evento Click 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 o valor StandardClick de ControlStyles como true para que esse evento seja gerado.You must set the StandardClick value of ControlStyles to true for this event to be raised.

Observação

Os eventos a seguir não são gerados para a classe TabControl, a menos que haja pelo menos um TabPage na coleção TabControl.TabPages: Click, DoubleClick, MouseDown, MouseUp, MouseHover, MouseEnter, MouseLeave e 0.The 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 de guia (onde os nomes de TabPage 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 da guia, o TabPage 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.

Observações para herdeirosNotes to inheritors

Herdar de um controle de Windows Forms padrão e alterar os valores de StandardClick ou StandardDoubleClick de ControlStyles para true pode causar um comportamento inesperado ou não ter nenhum efeito se o controle não oferecer suporte aos eventos Click ou DoubleClick.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 evento (Click ou DoubleClick) é 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, DateTimePicker, HScrollBar, VScrollBarMonthCalendar, DateTimePicker, HScrollBar, VScrollBar nenhumnone nenhumnone nenhumnone nenhumnone nenhumnone nenhumnone nenhumnone nenhumnone nenhumnone nenhumnone
Button, CheckBox, RichTextBox, RadioButtonButton, CheckBox, RichTextBox, RadioButton Clique emClick Clique em, clique emClick, Click nenhumnone nenhumnone nenhumnone nenhumnone nenhumnone nenhumnone nenhumnone nenhumnone
ListBox, CheckedListBox, ComboBoxListBox, CheckedListBox, ComboBox Clique emClick Clique em, DoubleClickClick, DoubleClick nenhumnone nenhumnone nenhumnone nenhumnone nenhumnone nenhumnone nenhumnone nenhumnone
TextBox, DomainUpDown, NumericUpDownTextBox, DomainUpDown, NumericUpDown Clique emClick Clique em, DoubleClickClick, DoubleClick nenhumnone nenhumnone nenhumnone nenhumnone nenhumnone nenhumnone nenhumnone nenhumnone
* TreeView, * ListView* TreeView, * ListView Clique emClick Clique em, DoubleClickClick, DoubleClick Clique emClick Clique em, DoubleClickClick, DoubleClick nenhumnone nenhumnone nenhumnone nenhumnone nenhumnone nenhumnone
ProgressBar, TrackBarProgressBar, 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, DataGrid, Label, LinkLabel, Panel, GroupBox, PictureBox, Splitter, StatusBar, ToolBar, TabPage, ** TabControlForm, DataGrid, Label, LinkLabel, Panel, GroupBox, PictureBox, Splitter, StatusBar, ToolBar, 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 filho (TreeNode ou ListViewItem).* The mouse pointer must be over a child object (TreeNode or ListViewItem).

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

Aplica-se a

Veja também