See Also Example
Form (not MDI form), check box, combo box , command button , directory list box , file list box , frame , grid , image , label , list box , menu , OLE control , option button , picture box , text box .
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 focus ,
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 Cancel 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 Value 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 array 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: MouseDown , MouseUp , 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.
Mousedown, MouseUp Events
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