Freetutes.com

VB6 beginners tutorial - Learn VB6

Advanced VB6 tutorial - Learn Advanced VB6

VB .NET - Learn Visual Basic .NET

Systems Analysis - System analysis and Design tutorial for Software Engineering


You are here: Visual Basic > Advanced VB6 tutorial > Chapter 3

The Click Event in VB6

A control's Click event fires when the control is enabled and the user both presses and releases a mouse button while the mouse pointer is over the control. If the mouse pointer is over a disabled control or if the mouse cursor is over a blank area of the form, then the form receives the Click event.

The Click event is easy to understand, because it represents a common user action that occurs dozens of times during a single session in any Windows-based application.

Notice that in our definition of the Click event in the first paragraph, the user must both press and release the mouse button over the same control. The Click event won't occur if the user presses the mouse button over one control and then moves the mouse pointer off the control to release it. The same goes for a form's Click event:

The user must both press and release the mouse button over an exposed area of the form or over a disabled control in order for the form to receive the Click event.

The Click event can also fire when the user presses a control's access key. The following controls support the Click event as noted:

  • CommandButton Only the left (or, for left-handed mice, the primary) mouse button fires a Click event for this control. Pressing Enter or SpaceBar when a CommandButton has focus will fire the Click event. Programmatically setting its Value property to True will cause the Click event procedure to run but will not fire the Click event.
  • Label Left or right mouse button fires a Click event.
  • TextBox Left or right mouse button fires a Click event.

NOTE1: Choosing the Proper Mouse Event Procedure One of the tricks to learning Visual Basic is to determine which events to use in a given situation.

When attempting to determine which mouse button was selected, many new programmers do not see much difference between the Click, MouseUp, and MouseDown events. The difference between any two events within VB lies in when they occur with respect to each other. The Click event procedure is the preferred place to detect a user's intentions.

The reason for using the Click event is to allow the user forgiveness. If the user did not mean to click on your object, or has pressed the button and then realized he did not want to, the mouse could still be removed from the object. If the mouse is dragged outside the area of the object, the MouseUp event will still occur. The Click event, however, will not occur.

Allowing your program to be forgiving means the user will have an easier time using the software, instead of fearing the next mistake.

NOTE2: Pressing and Releasing the Mouse Button To distinguish between pressing and releasing the mouse button, see the discussion of MouseUp and MouseDown events later in this


  

 

<< Previous | Contents | Next >>

Home | About Us | Privacy Policy | Contact Us

Copyright © Freetutes.com | All Rights Reserved