LPARAMETERS nButton, nShift, nXCoord, nYCoord
This.Visible = .F.
MOUSE CLICK
* Leave out this next line at your peril!!
DOEVENTS
This.Visible = .T.
* update the label with the item selected.
ThisForm.Label2.Caption = ThisForm.List1.Value
That's all. Run the form and as you move the mouse over the listbox, the highlight also moves and the label shows that the value is being changed.
Often I design a button or some other control on a form that will involve a number of other controls. When I am satisfied with the result, I select all the controls involved and save them as a Class for later use. This puts all the controls into a container and I can easily add the relevant PEM's to the class to complete it.
For instance to achieve this button I used an image control on top of which I dropped a Label control. When the mouse moves over the "button" I want the highlight to change. For this I just hook into the MouseEnter and MouseLeave events and change the image there. However when I add a label on top of the image control, things change.

What I have noticed is that most dev's just add code to the Label MouseEnter/MouseLeave events to call the image MouseEnter/MouseLeave which does the actual switching of the images. At first this may seem ok, but on closer examination you can see that something else is taking place that will cause the "button" control to flash and flicker.
This image shows the problem.

The MouseEnter of the image first fires and the code is run to change the image. If you now move off the image it changes back. So far so good.
However if you now move the cursor over the label, the events that occur are :
1. The MouseLeave of the image fires - image is changed
2. The MouseEnter of the label fires which fires the MouseEnter of the image which changes the image again.
The same sequence occurs when the mouse is moved off the label but in reverse. This flipping of the image twice causes the flicker.
I received an email once about my "GlassButtons", where the DEV had added a Label control over it and did as I did above. His complaint was that the flicker was terrible. The shape came to his rescue.
It is very easy to solve this. Just drop a shape control or if you want the control to get focus (tab order) use an invisible button.
In my image the shape is shown with the green border, but you will hide it by making the BorderStyle = 0. Also it will need to be sized either at design time or at runtime (friom the init) so that it completely covers the image and label controls.
Now all that is needed is to move all code to flip the images into this shape control's MouseEnter and MouseMove. No code is needed in either the image or label controls. You can hook the click to the parent container click.
Now moving the mouse over the control will only fire the MouseEnter once and when you move off, the MouseLeave once.
Goodbye flicker.
More tips & tricks soon.
Note that there is no download since there are only a few lines of code and the technique is the main thing.
Unfortunately because of the amount of junk mail being generated from the weblog I have switched off comments. Please post your comments, if any, at www.foxite.com