Control.Click Control.Click Control.Click Control.Click Event

Definición

Se produce cuando se hace clic en el control.Occurs when the control is clicked.

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

Ejemplos

El siguiente ejemplo de código muestra la Click eventos en un controlador 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

Comentarios

El Click evento pasa una EventArgs a su controlador de eventos, por lo tanto, sólo indica que se ha producido un clic.The Click event passes an EventArgs to its event handler, so it only indicates that a click has occurred. Si necesita información más específica de mouse (botón, número de clics, rotación de la rueda o ubicación), use el MouseClick eventos.If you need more specific mouse information (button, number of clicks, wheel rotation, or location), use the MouseClick event. Sin embargo, el MouseClick evento no se genera si se debe hacer clic en acción distinto del mouse, como presionar la tecla ENTRAR.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.

Un doble clic viene determinada por la configuración del mouse del sistema operativo del usuario.A double-click is determined by the mouse settings of the user's operating system. El usuario puede establecer el tiempo entre los clics de un botón del mouse que debe considerarse como un doble clic y no como dos clics.The user can set the time between clicks of a mouse button that should be considered a double-click rather than two clicks. El Click evento se desencadena cada vez que se hace doble clic en un control.The Click event is raised every time a control is double-clicked. Por ejemplo, si tiene controladores de eventos para el Click y DoubleClick eventos de un Form, Click y DoubleClick se generan eventos cuando se hace doble clic en el formulario y se llama a ambos métodos.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. Si se hace doble clic en un control y que el control no admite la DoubleClick eventos, el Click evento podría generarse dos veces.If a control is double-clicked and that control does not support the DoubleClick event, the Click event might be raised twice.

Debe establecer el StandardClick valor ControlStyles a true para que se genere este evento.You must set the StandardClick value of ControlStyles to true for this event to be raised.

Nota

Los siguientes eventos no se generan para el TabControl a menos que haya al menos una de las clases TabPage en el TabControl.TabPages colección: Click, DoubleClick, MouseDown, MouseUp, MouseHover, MouseEnter, MouseLeave y MouseMove.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. Si hay al menos un TabPage en la colección, y el usuario interactúa con el encabezado del control de ficha (donde el TabPage aparecen nombres), el TabControl provoca el evento adecuado.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. Sin embargo, si la interacción del usuario está dentro del área de cliente de la página de ficha, el TabPage provoca el evento adecuado.However, if the user interaction is within the client area of the tab page, the TabPage raises the appropriate event.

Para obtener más información sobre el manejo de eventos, consulte controlar y provocar eventos.For more information about handling events, see Handling and Raising Events.

Notas para los herederosNotes to inheritors

Heredar de un control de Windows Forms estándar y cambiar el StandardClick o StandardDoubleClick valores de ControlStyles a true puede provocar un comportamiento inesperado o no tienen ningún efecto en absoluto si el control no admite el Click o DoubleClickeventos.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.

En la tabla siguiente se enumera los controles de formularios Windows Forms y qué evento (Click o DoubleClick) se produce en respuesta a la acción del mouse especificada.The following table lists Windows Forms controls and which event (Click or DoubleClick) is raised in response to the mouse action specified.

ControlControl Clic del Mouse izquierdoLeft Mouse Click Haga doble clic en el primario del MouseLeft Mouse Double Click Haga clic derecho del MouseRight Mouse Click Haga doble clic en el secundario del MouseRight Mouse Double Click Haga clic central del MouseMiddle Mouse Click Haga doble clic en la central del MouseMiddle Mouse Double Click Haga clic en de XButton1 del MouseXButton1 Mouse Click XButton1 del Mouse haga doble clic enXButton1 Mouse Double-Click Haga clic en de XButton2 del MouseXButton2 Mouse Click XButton2 del Mouse haga doble clic enXButton2 Mouse Double-Click
MonthCalendar, DateTimePicker, HScrollBar, VScrollBarMonthCalendar, DateTimePicker, HScrollBar, VScrollBar ningunanone ningunanone ningunanone ningunanone ningunanone ningunanone ningunanone ningunanone ningunanone ningunanone
Button, CheckBox, RichTextBox, RadioButtonButton, CheckBox, RichTextBox, RadioButton Haga clicClick Haga clic en, haga clic enClick, Click ningunanone ningunanone ningunanone ningunanone ningunanone ningunanone ningunanone ningunanone
ListBox, CheckedListBox, ComboBoxListBox, CheckedListBox, ComboBox Haga clicClick Click, DoubleClickClick, DoubleClick ningunanone ningunanone ningunanone ningunanone ningunanone ningunanone ningunanone ningunanone
TextBox, DomainUpDown, NumericUpDownTextBox, DomainUpDown, NumericUpDown Haga clicClick Click, DoubleClickClick, DoubleClick ningunanone ningunanone ningunanone ningunanone ningunanone ningunanone ningunanone ningunanone
* TreeView, * ListView* TreeView, * ListView Haga clicClick Click, DoubleClickClick, DoubleClick Haga clicClick Click, DoubleClickClick, DoubleClick ningunanone ningunanone ningunanone ningunanone ningunanone ningunanone
ProgressBar, TrackBarProgressBar, TrackBar Haga clicClick Haga clic en, haga clic enClick, Click Haga clicClick Haga clic en, haga clic enClick, Click Haga clicClick Haga clic en, haga clic enClick, Click Haga clicClick Haga clic en, haga clic enClick, Click Haga clicClick Haga clic en, haga clic enClick, Click
Form, DataGrid, Label, LinkLabel, Panel, GroupBox, PictureBox, Splitter, StatusBar, ToolBar, TabPage, ** TabControlForm, DataGrid, Label, LinkLabel, Panel, GroupBox, PictureBox, Splitter, StatusBar, ToolBar, TabPage, ** TabControl Haga clicClick Click, DoubleClickClick, DoubleClick Haga clicClick Click, DoubleClickClick, DoubleClick Haga clicClick Click, DoubleClickClick, DoubleClick Haga clicClick Click, DoubleClickClick, DoubleClick Haga clicClick Click, DoubleClickClick, DoubleClick

* Debe ser el puntero del mouse sobre un objeto secundario (TreeNode o ListViewItem).* The mouse pointer must be over a child object (TreeNode or ListViewItem).

** Los TabControl debe tener al menos un TabPage en su TabPages colección.** The TabControl must have at least one TabPage in its TabPages collection.

Se aplica a

Consulte también: