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

En el ejemplo de código siguiente Click se muestra el evento 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 eventoEventArgs pasa a su controlador de eventos, por lo que solo 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 del mouse (botón, número de clics, rotación de la rueda o ubicación), use MouseClick el evento.If you need more specific mouse information (button, number of clicks, wheel rotation, or location), use the MouseClick event. Sin embargo, MouseClick el evento no se producirá si el clic se produce por una acción distinta de la 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.

La configuración del mouse del sistema operativo del usuario determina el doble clic.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 genera 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 Click para los eventos y DoubleClick de un Form, se generan Click los DoubleClick eventos y 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 dicho control no admite el DoubleClick evento, el Click evento podría producirse 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 de ControlStyles en 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 eventos siguientes no se generan para la TabControl clase a menos que haya al menos TabPage un en TabControl.TabPages la colección Click: DoubleClick, MouseDown, MouseUp, MouseHover, MouseEnter,, MouseLeave y .MouseMoveThe 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 pestaña (donde aparecen los TabPage TabControl nombres), genera 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 con el usuario se encuentra en el área cliente de la TabPage página de ficha, genera 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 a los herederosNotes to inheritors

Heredar de un control de Windows Forms estándar y cambiar StandardClick los StandardDoubleClick valores o ControlStyles de true a puede producir Click un comportamiento inesperado o no tener ningún efecto si el control no admite 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 enumeran Windows Forms controles yClick qué DoubleClickevento (o) se produce como 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 con el botón primarioLeft Mouse Click Doble clic con el botón primarioLeft Mouse Double Click Clic con el botón secundario del mouseRight Mouse Click Doble clic con el botón secundario del mouseRight Mouse Double Click Clic con el botón central del mouseMiddle Mouse Click Doble clic con el botón centralMiddle Mouse Double Click XButton1 clic del mouseXButton1 Mouse Click Doble clic con el mouse de XButton1XButton1 Mouse Double-Click XButton2 clic del mouseXButton2 Mouse Click Doble clic con el mouse de XButton2XButton2 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 enClick, Click ningunanone ningunanone ningunanone ningunanone ningunanone ningunanone ningunanone ningunanone
ListBox, CheckedListBox, ComboBoxListBox, CheckedListBox, ComboBox Haga clicClick Haga clic en, DoubleClickClick, DoubleClick ningunanone ningunanone ningunanone ningunanone ningunanone ningunanone ningunanone ningunanone
TextBox, DomainUpDown, NumericUpDownTextBox, DomainUpDown, NumericUpDown Haga clicClick Haga clic en, DoubleClickClick, DoubleClick ningunanone ningunanone ningunanone ningunanone ningunanone ningunanone ningunanone ningunanone
* TreeView, * ListView* TreeView, * ListView Haga clicClick Haga clic en, DoubleClickClick, DoubleClick Haga clicClick Haga clic en, DoubleClickClick, DoubleClick ningunanone ningunanone ningunanone ningunanone ningunanone ningunanone
ProgressBar, TrackBarProgressBar, TrackBar Haga clicClick Haga clic enClick, Click Haga clicClick Haga clic enClick, Click Haga clicClick Haga clic enClick, Click Haga clicClick Haga clic enClick, Click Haga clicClick 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 Haga clic en, DoubleClickClick, DoubleClick Haga clicClick Haga clic en, DoubleClickClick, DoubleClick Haga clicClick Haga clic en, DoubleClickClick, DoubleClick Haga clicClick Haga clic en, DoubleClickClick, DoubleClick Haga clicClick Haga clic en, DoubleClickClick, DoubleClick

*El puntero del mouse debe estar sobre un objeto secundarioTreeNode ( ListViewItemo).* The mouse pointer must be over a child object (TreeNode or ListViewItem).

* * El 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: