Control.Click Événement

Définition

Se produit suite à un clic sur le contrôle.Occurs when the control is clicked.

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

Exemples

L’exemple de code suivant montre l’événement Click dans un gestionnaire d’événements.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

Remarques

L’événement Click passe une EventArgs à son gestionnaire d’événements, de sorte qu’il n’indique qu’un clic a été effectué.The Click event passes an EventArgs to its event handler, so it only indicates that a click has occurred. Si vous avez besoin d’informations de souris plus spécifiques (bouton, nombre de clics, rotation de la roulette ou emplacement), utilisez l’événement MouseClick.If you need more specific mouse information (button, number of clicks, wheel rotation, or location), use the MouseClick event. Toutefois, l’événement MouseClick n’est pas déclenché si le clic est provoqué par une action autre que celle de la souris, par exemple en appuyant sur la touche entrée.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 double-clic est déterminé par les paramètres de la souris du système d’exploitation de l’utilisateur.A double-click is determined by the mouse settings of the user's operating system. L'utilisateur peut définir le délai qui détermine si les clics effectués sur un bouton de souris sont considérés comme un double-clic ou comme deux clics.The user can set the time between clicks of a mouse button that should be considered a double-click rather than two clicks. L’événement Click est déclenché chaque fois que l’utilisateur double-clique sur un contrôle.The Click event is raised every time a control is double-clicked. Par exemple, si vous avez des gestionnaires d’événements pour les événements Click et DoubleClick d’un Form, les événements Click et DoubleClick sont déclenchés lorsque vous double-cliquez sur le formulaire et que les deux méthodes sont appelées.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 vous double-cliquez sur un contrôle et que ce contrôle ne prend pas en charge l’événement DoubleClick, l’événement Click peut être déclenché deux fois.If a control is double-clicked and that control does not support the DoubleClick event, the Click event might be raised twice.

Vous devez définir la valeur StandardClick de ControlStyles sur true pour que cet événement soit déclenché.You must set the StandardClick value of ControlStyles to true for this event to be raised.

Notes

Les événements suivants ne sont pas déclenchés pour la classe TabControl, à moins qu’il y ait au moins un TabPage dans la collection TabControl.TabPages : Click, DoubleClick, MouseDown, MouseUp, MouseHover, MouseEnter, MouseLeave et 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. S’il existe au moins un TabPage dans la collection, et que l’utilisateur interagit avec l’en-tête du contrôle onglet (où les noms TabPage apparaissent), le TabControl déclenche l’événement approprié.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. Toutefois, si l’interaction de l’utilisateur se trouve dans la zone cliente de la page d’onglets, la TabPage déclenche l’événement approprié.However, if the user interaction is within the client area of the tab page, the TabPage raises the appropriate event.

Pour plus d'informations sur la gestion des événements, voir gestion et déclenchement d’événements.For more information about handling events, see Handling and Raising Events.

Remarques à l’héritageNotes to inheritors

L’héritage d’un contrôle de Windows Forms standard et la modification des valeurs StandardClick ou StandardDoubleClick de ControlStyles en true peuvent entraîner un comportement inattendu ou n’avoir aucun effet si le contrôle ne prend pas en charge les événements 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.

Le tableau suivant répertorie Windows Forms contrôles et l’événement (Click ou DoubleClick) est déclenché en réponse à l’action de la souris spécifiée.The following table lists Windows Forms controls and which event (Click or DoubleClick) is raised in response to the mouse action specified.

ContrôleControl Cliquer avec le bouton gauche de la sourisLeft Mouse Click Double-clic de la souris gaucheLeft Mouse Double Click Clic droit de la sourisRight Mouse Click Double-clic de droite de la sourisRight Mouse Double Click Clic de souris du milieuMiddle Mouse Click Double-clic de la souris du milieuMiddle Mouse Double Click Le bouton XButton1 clic de sourisXButton1 Mouse Click Double-clic de la souris le bouton XButton1XButton1 Mouse Double-Click XButton2 clic de sourisXButton2 Mouse Click Double-clic de la souris XButton2XButton2 Mouse Double-Click
MonthCalendar, DateTimePicker, HScrollBar, VScrollBarMonthCalendar, DateTimePicker, HScrollBar, VScrollBar nonenone nonenone nonenone nonenone nonenone nonenone nonenone nonenone nonenone nonenone
Button, CheckBox, RichTextBox, RadioButtonButton, CheckBox, RichTextBox, RadioButton ClicClick Cliquez sur, surClick, Click nonenone nonenone nonenone nonenone nonenone nonenone nonenone nonenone
ListBox, CheckedListBox, ComboBoxListBox, CheckedListBox, ComboBox ClicClick Click, DoubleClickClick, DoubleClick nonenone nonenone nonenone nonenone nonenone nonenone nonenone nonenone
TextBox, DomainUpDown, NumericUpDownTextBox, DomainUpDown, NumericUpDown ClicClick Click, DoubleClickClick, DoubleClick nonenone nonenone nonenone nonenone nonenone nonenone nonenone nonenone
* TreeView, * ListView* TreeView, * ListView ClicClick Click, DoubleClickClick, DoubleClick ClicClick Click, DoubleClickClick, DoubleClick nonenone nonenone nonenone nonenone nonenone nonenone
ProgressBar, TrackBarProgressBar, TrackBar ClicClick Cliquez sur, surClick, Click ClicClick Cliquez sur, surClick, Click ClicClick Cliquez sur, surClick, Click ClicClick Cliquez sur, surClick, Click ClicClick Cliquez sur, surClick, Click
Form, DataGrid, Label, LinkLabel, Panel, GroupBox, PictureBox, Splitter, StatusBar, ToolBar, TabPage, ** TabControlForm, DataGrid, Label, LinkLabel, Panel, GroupBox, PictureBox, Splitter, StatusBar, ToolBar, TabPage, ** TabControl ClicClick Click, DoubleClickClick, DoubleClick ClicClick Click, DoubleClickClick, DoubleClick ClicClick Click, DoubleClickClick, DoubleClick ClicClick Click, DoubleClickClick, DoubleClick ClicClick Click, DoubleClickClick, DoubleClick

* le pointeur de la souris doit être sur un objet enfant (TreeNode ou ListViewItem).* The mouse pointer must be over a child object (TreeNode or ListViewItem).

* * Le TabControl doit avoir au moins un TabPage dans sa collection TabPages.** The TabControl must have at least one TabPage in its TabPages collection.

S’applique à

Voir aussi