here are a couple of tips for getting things done with your classes using the shape control.

with a listbox control, you have to actually click on it before any row is selected. if, for any reason you wanted to be able to just move your mouse over it and have a row selected, you will find that you cannot achieve this with the plain control. that is because this behaviour is not native.

but given that you may want this specific effect, and remember that this technique can be used for other controls and your custom classes as well, here we go:

after you have setup your listbox to how you want it, from the toolbar select and drop a shape on the form and size it to fit exactly around your list, excluding the scrollbars. you could do this programatically, using sysmetric, but i leave that to you. the red box indicates the size and position of the shape on your listbox.

also drop a simple label control below the listbox to show the result. set its :

autosize = .t.

backstyle = 0

set the following properties of the shape:

backstyle = 0 - transparent

borderstyle = 0 - transparent

double click the shape and add this code in the mousemove method:


lparameters nbutton, nshift, nxcoord, nycoord

this.visible = .f.

mouse click

* leave out this next line at your peril!!


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

Leave a Reply

Your email address will not be published. Required fields are marked *