BeforeAddTable

Click, RightClick, MiddleClick, DblClick

These events let you do something when the user clicks or double-clicks on an object. They also fire under a bunch of other circumstances. The Click method is likely to contain code more often than almost any other, especially for button objects.

Usage

PROCEDURE oObject.Click | oObject.RightClick           | oObject.MiddleClick | oObject.DblClick [ LPARAMETERS nIndex ]
The nIndex parameter is relevant only when working with control arrays, an occurrence we consider unlikely in most cases.

Although the names of these events are quite explicit, in fact, both Click and DblClick are fired by quite a number of occurrences other than the ones their names imply (see the next paragraph for some examples). Check Help for a complete list of things that fire Click and DblClick.

Basically, Click is fired by a mouse click on an object or by anything that's equivalent to that mouse click. So, for example, choosing a Default button on a form by pressing Enter fires that button's Click. So does pressing Spacebar on a button or check box. As for DblClick, it's the same idea—it's fired by double-clicks and by anything that's equivalent to a double-click from the control's point of view. Having said that, it's worth noting that pressing the context menu button on the keyboard does not fire RightClick for the object under the mouse.

Since we can distinguish between mouse actions and keyboard actions with events like KeyPress and MouseDown, we're generally happy about the overloading of Click and DblClick. It would be a pain to have to call a button's Click method from some other method every time the user chose a button by pressing Spacebar or Enter.

One firing sequence is strange enough to warrant comment. In a list, using the arrow keys to move through the data fires both the When and Click events for the list. However, moving with the PgUp, PgDn, Home or End keys fires only the When.

It's nearly impossible to get a grid's Click to fire—normally the mouse events are routed to the headers or the controls in the grid. To get the grid's mouse events to fire, you have to click in an area on the inside of the grid that's unoccupied by a record—that is, below the last record or to the right of the last column.

In VFP 5 and VFP 6, clicking on the current page of a page frame in an area containing no control fires just the page's Click, while clicking on the tab of a page sometimes fires first the page frame's Click, then the form's Click, and finally the page's Click. In VFP 3, the sequence is the same, except that, in the second case, the form's Click doesn't fire. We can't see any reason why the form's Click fires. This bug appears to be fixed in VFP 7.


Clicking the mouse is not a single event. Before Click fires, both MouseDown and MouseUp fire. You can usually prevent Click events from occurring by putting NoDefault in MouseUp.

Putting NoDefault in MouseUp doesn't prevent the Click events in Grids or Headers. We see different behavior in different versions as to what events NoDefault prevents in what controls. On the whole, we think a NoDefault in either MouseUp or MouseDown should prevent all the Click events from firing in every control, and we're sure not seeing that.


If you want to be sure you're suppressing a particular Click event, test your specific case.

RightClick is important mostly for attaching context menus (also known as shortcut menus or right-click menus) to objects.

MiddleClick was added in VFP 5 to accommodate three-button mouses (mice? rodents?). The introduction of Microsoft's IntelliMouse gave us a chance to test this one out—the mouse wheel can be pressed to produce a middle-click.

In general, it's best not to assume that your users have a middle-button-capable device unless you're coding for a very small, well-known audience. (Of course, in general, it's not a good idea to assume that users have a mouse. We've all had the experience of working on a machine with a dead mouse. The best applications let us work anyway.)

Example

* Typical Click code processes the user's action. * A command button labeled Save might have: ThisForm.SaveRecord()

See Also

Mouse, MouseDown, MouseEnter, MouseLeave, MouseUp, MouseWheel, _DblClick


View Updates

Copyright © 2002 by Tamar E. Granor, Ted Roche, Doug Hennig, and Della Martin. All Rights Reserved.



Hacker's Guide to Visual FoxPro 7. 0
Hackers Guide to Visual FoxPro 7.0
ISBN: 1930919220
EAN: 2147483647
Year: 2001
Pages: 899

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net