Export (0) Print
Expand All

Visual Basic Reference

Visual Studio 6.0

Click Event

See Also    Example    Applies To

Occurs when the user presses and then releases a mouse button over an object. It can also occur when the value of a control is changed.

For a Form object, this event occurs when the user clicks either a blank area or a disabled control. For a control, this event occurs when the user:

  • Clicks a control with the left or right mouse button. With a CheckBox, CommandButton, Listbox, or OptionButton control, the Click event occurs only when the user clicks the left mouse button.

  • Selects an item in a ComboBox or ListBox control, either by pressing the arrow keys or by clicking the mouse button.

  • Presses the SPACEBAR when a CommandButton, OptionButton, or CheckBox control has the focus.

  • Presses ENTER when a form has a CommandButton control with its Default property set to True.

  • Presses ESC when a form has a Cancel button a CommandButton control with its Cancel property set to True.

  • Presses an access key for a control. For example, if the caption of a CommandButton control is "&Go", pressing ALT+G triggers the event.

You can also trigger the Click event in code by:

  • Setting a CommandButton control's Value property to True.

  • Setting an OptionButton control's Value property to True.

  • Changing a CheckBox control's Value property setting.

Syntax

Private Sub Form_Click( )

Private Sub object_Click([index As Integer])

The Click event syntax has these parts:

Part Description
object An object expression that evaluates to an object in the Applies To list.
index An integer that uniquely identifies a control if it's in a control array.

Remarks

Typically, you attach a Click event procedure to a CommandButton control, Menu object, or PictureBox control to carry out commands and command-like actions. For the other applicable controls, use this event to trigger actions in response to a change in the control.

You can use a control's Value property to test the state of the control from code. Clicking a control generates MouseDown and MouseUp events in addition to the Click event. The order in which these three events occur varies from control to control. For example, for ListBox and CommandButton controls, the events occur in this order: MouseDown, Click, MouseUp. But for FileListBox, Label, or PictureBox controls, the events occur in this order: MouseDown, MouseUp, and Click. When you're attaching event procedures for these related events, be sure that their actions don't conflict. If the order of events is important in your application, test the control to determine the event order.

Note   To distinguish between the left, right, and middle mouse buttons, use the MouseDown and MouseUp events.

If there is code in the Click event, the DblClick event will never trigger, because the Click event is the first event to trigger between the two. As a result, the mouse click is intercepted by the Click event, so the DblClick event doesn't occur.

Show:
© 2015 Microsoft