The Unofficial Newsletter of Delphi Users - by Robert Vivrette



Highlighting Edit Boxes

by Eamonn Mulvihill - ucs@cableinet.co.uk

Herbert J. Beemster's article Give Your Editbox Some Attention! derived an edit box that display an extra border when it has focus. Great idea, but a real pain in the #!$e deriving a new control every time you wanted to add that functionality.

That set me thinking about an idea i had ages ago - to trap delphi's Cn_FocusChanged message, and draw a border around any control that has just received the focus.

Attached is the control TucsFocus (delphi 3) - basically it waits for a control to send out a Cn_FocusChanged message, and then resizes itself and positions inself *under* the focused control to produce a border effect.

To place the TucsFocus under and control on a form, it is necessary to change it's parent - this caused a problem because when the message handler is active, the parent is looping through it's controls list to notify all it's children, so changing the parent in the message handler resulted in an index out of bounds exception.  To handle this i had to post a WM_USER message to the control which would then be processed after all of the parent's children had been notified.  It is the WM_USER message handler that does all the work.

I've added two properties: Color (naturally) and BorderSize (the width of the border).

I dare say it could be improved - for instance not using the WM_USER message - but i hope some of you find a use for it.

Eamonn Mulvihill
Consultancy and programing services