Click Event

See Also2AVEEPP              ExamplePZJ1NL>Low

Applies To

Form14TJ2LN (not MDI form), check box9P3BU5, combo box1YZXFF6, command buttonXJSPC0, directory list boxO9U5A0, file list box1M6S8UX, frame1KX6ZP8, grid2VGT0PT, image9A4FCA, label3MNIZ8D, list boxG11UCK, menuBKDT1F, OLE control2HQDVVU, option buttonJYBO08, picture box31MYIWX, text boxYPYZDG.


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

For a form, 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 check box, command button or option button the Click event only occurs when the user clicks the left mouse button.

         Selects an item in a combo box or list box, either by pressing the arrow keys or by clicking the mouse button.

         Presses the Spacebar when a command button, option button, or check box has the focus1L3L8ZY,

         Presses Enter when a form has a command button with its Default property set to True.

         Presses Esc when a form has a Cancel buttona command button with its CancelKQ58YS property set to True.

         Presses an access key combination for a control.  For example, if the caption of a command button is "&Go", then pressing Alt+G triggers the event.


You can also trigger the Click event in code by:

         Setting a command button's Value5OIC88B property to True.

         Setting an option button's Value property to True.

         Changing a check box's Value property setting.



Sub Form_Click ( )

Sub ctlname_Click (Index As Integer)


The argument Index uniquely identifies a control if it is in a control array8G7Y0UU.  Typically, you attach a Click procedure to a command button, menu, or picture box 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 for the state of the control from code.  When a Click event is generated for a file list box, list box, label, or picture box, Visual Basic also calls the related events in this order:  MouseDownD0VNMJ, MouseUpD0VNMJ, Click.  When you're attaching procedures for these related events, be sure that their actions don't conflict.


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


See Also


Cancel PropertyKQ58YS

DblClick Event2UG5QK1

Default Property31OHP7N

Mousedown, MouseUp EventsD0VNMJ


Programmer's Guide:

Chapter 12, "Responding to Mouse Events"

Click Event Example

In this example, each time a picture box is clicked it moves diagonally across a form.  To try this example, paste the code into the Declarations section of a form that contains a picture box positioned at the lower left corner of the form.  Then press F5 and click the picture box.

Sub Picture1_Click ()

   Picture1.Move Picture1.Left + 750, Picture1.Top - 550

End Sub