Click Event

Purpose

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.

Syntax

Sub object_Click([index As Integer])

object:Ocx Object
index:iexp

Description

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, Command, ListBox, or Option 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 Command, Option, or CheckBox control has the focus.

- Presses ENTER when a form has a Command control with its Default property set to True.

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

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

You can also trigger the Click event in code by:

- Setting a Command control's Value property to True.

- Setting an Option control's Value property to True.

- Changing a CheckBox control's Value property setting.

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 Command controls, the events occur in this order: MouseDown, Click, and MouseUp. But for a Label control, the events occur in this order: MouseDown, MouseUp, and Click.

Example

Form frm1 = "(Dbl)Click Event", 20, 20, 300, 300

Ocx Command cmd(1) = "cmd1", 10, 10, 80, 24

Ocx Command cmd(2) = "cmd2", 10, 40, 80, 24

Ocx Command cmd(3) = "cmd3", 10, 70, 80, 24

Do

Sleep

Until Me Is Nothing

 

Sub cmd_Click(Index%)

Text 100, 30, "Click at " + Str(Index)

EndSub

 

Sub cmd_DblClick(Index%)

Text 100, 30, "DblClick at " + Str(Index)

EndSub

Remarks

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.

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.

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

See Also

Form, DblClick, MouseDown, MouseDblClick

{Created by Sjouke Hamstra; Last updated: 25/09/2014 by James Gaite}