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

Definizione

Si verifica quando si fa clic sul controllo.Occurs when the control is clicked.

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

Esempi

Nell'esempio di codice riportato di Click seguito viene illustrato l'evento in un gestore eventi.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

Commenti

L' Click evento passa un EventArgs oggetto al relativo gestore eventi, quindi indica solo che si è verificato un clic.The Click event passes an EventArgs to its event handler, so it only indicates that a click has occurred. Se sono necessarie informazioni più specifiche del mouse (pulsante, numero di clic, rotazione della rotellina o posizione), MouseClick usare l'evento.If you need more specific mouse information (button, number of clicks, wheel rotation, or location), use the MouseClick event. Tuttavia, l' MouseClick evento non verrà generato se il clic è causato da un'azione diversa da quella del mouse, ad esempio premendo il tasto INVIO.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 doppio clic è determinato dalle impostazioni del mouse del sistema operativo dell'utente.A double-click is determined by the mouse settings of the user's operating system. L'utente può impostare un intervallo tra i clic effettuati con un pulsante del mouse in modo che debbano essere considerati come un doppio clic anziché come due clic distinti.The user can set the time between clicks of a mouse button that should be considered a double-click rather than two clicks. L' Click evento viene generato ogni volta che si fa doppio clic su un controllo.The Click event is raised every time a control is double-clicked. Se, ad esempio, si dispone di gestori eventi per Click gli DoubleClick eventi e di Formun, Click gli DoubleClick eventi e vengono generati quando si fa doppio clic sul form ed entrambi i metodi vengono chiamati.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 si fa doppio clic su un controllo e il controllo non supporta l' DoubleClick evento, è possibile che l' Click evento venga generato due volte.If a control is double-clicked and that control does not support the DoubleClick event, the Click event might be raised twice.

È necessario impostare il StandardClick valore di ControlStyles su true per generare questo evento.You must set the StandardClick value of ControlStyles to true for this event to be raised.

Nota

Gli eventi seguenti non vengono generati per la TabControl classe, a meno che non esista almeno TabPage un oggetto TabControl.TabPages nella raccolta Click: DoubleClick, MouseDown, MouseUp, MouseHover, MouseEnter,, MouseLeave e .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. Se è presente almeno un TabPage oggetto nella raccolta e l'utente interagisce con l'intestazione del controllo Tab (dove vengono visualizzati i TabPage TabControl nomi), genera l'evento appropriato.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. Tuttavia, se l'interazione dell'utente si trova all'interno dell'area client della pagina della TabPage scheda, genera l'evento appropriato.However, if the user interaction is within the client area of the tab page, the TabPage raises the appropriate event.

Per ulteriori informazioni sulla gestione degli eventi, consultare gestione e generazione di eventi.For more information about handling events, see Handling and Raising Events.

Note per gli erediNotes to inheritors

Ereditare da un controllo Windows Forms standard e modificare i StandardClick valori StandardDoubleClick o di ControlStyles in true può causare Click un comportamento imprevisto o non avere alcun effetto se il controllo non supporta o DoubleClickeventi.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.

Nella tabella seguente sono elencati Windows Forms controlli e l'eventoClick ( DoubleClicko) generato in risposta all'azione del mouse specificata.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 il pulsante sinistro del mouseLeft Mouse Click Doppio clic con il pulsante sinistro del mouseLeft Mouse Double Click Clic con il pulsante destro del mouseRight Mouse Click Doppio clic con il pulsante destro del mouseRight Mouse Double Click Clic del mouse centraleMiddle Mouse Click Doppio clic con il mouseMiddle Mouse Double Click Clic del mouse XButton1XButton1 Mouse Click Doppio clic del mouse XButton1XButton1 Mouse Double-Click Clic del mouse XButton2XButton2 Mouse Click Doppio clic del mouse 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 Fare clic suClick Fare clic suClick, Click nonenone nonenone nonenone nonenone nonenone nonenone nonenone nonenone
ListBox, CheckedListBox, ComboBoxListBox, CheckedListBox, ComboBox Fare clic suClick Fare clic su, DoubleClickClick, DoubleClick nonenone nonenone nonenone nonenone nonenone nonenone nonenone nonenone
TextBox, DomainUpDown, NumericUpDownTextBox, DomainUpDown, NumericUpDown Fare clic suClick Fare clic su, DoubleClickClick, DoubleClick nonenone nonenone nonenone nonenone nonenone nonenone nonenone nonenone
* TreeView, * ListView* TreeView, * ListView Fare clic suClick Fare clic su, DoubleClickClick, DoubleClick Fare clic suClick Fare clic su, DoubleClickClick, DoubleClick nonenone nonenone nonenone nonenone nonenone nonenone
ProgressBar, TrackBarProgressBar, TrackBar Fare clic suClick Fare clic suClick, Click Fare clic suClick Fare clic suClick, Click Fare clic suClick Fare clic suClick, Click Fare clic suClick Fare clic suClick, Click Fare clic suClick Fare clic suClick, Click
Form, DataGrid, Label, LinkLabel, Panel, GroupBox, PictureBox, Splitter, StatusBar, ToolBar, TabPage, ** TabControlForm, DataGrid, Label, LinkLabel, Panel, GroupBox, PictureBox, Splitter, StatusBar, ToolBar, TabPage, ** TabControl Fare clic suClick Fare clic su, DoubleClickClick, DoubleClick Fare clic suClick Fare clic su, DoubleClickClick, DoubleClick Fare clic suClick Fare clic su, DoubleClickClick, DoubleClick Fare clic suClick Fare clic su, DoubleClickClick, DoubleClick Fare clic suClick Fare clic su, DoubleClickClick, DoubleClick

*Il puntatore del mouse deve essere posizionato su un oggettoTreeNode figlio ListViewItem(o).* The mouse pointer must be over a child object (TreeNode or ListViewItem).

* * Il TabControl deve avere almeno un TabPage nella relativa TabPages raccolta.** The TabControl must have at least one TabPage in its TabPages collection.

Si applica a

Vedi anche