Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

highlight current control as user tabs through form 2

Status
Not open for further replies.

josephwalter

Programmer
Sep 16, 2002
80
US
I'd like to change the background color of each control on the form as the user tabs through them - in order to highlight where he/she is at on the form.

I know I could code a change in the BackColor property under the GotFocus and LostFocus of each control, but that doesn't feel like the most efficient route.

I thought something in the OnTimer event would work nicely: Change all the controls' BackColor properties to white and then give the control that has the focus a blue background color.

I vaguely remember seeing a code snippet before, but I've had no luck locating it. Can someone provide me a link or the code?
 
Inside the timer event, you would loop through the Form's controls collection, setting the background colors, and use the Me.ActiveControl to set the control with the focus.

That being said, I would not recommend that approach. The timer loop would have to be very short, resulting in a very process intensive application, since even if the user is idle, that timer process is still firing away. That would chew up a lot of processor cycles. Plus you'd have to deal with situation where control is passed to a command button, or similar type control which would not be part of the process. You would also have to make sure that you don't flicker the active control.

Using the Got and Lost focus event would be more efficient in terms of processor load since the process would only do what it had to do, and only when it was necessary.

Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
That thought had occured to me, but figured it was worth trying. I got the code working, using your "Me.ActiveControl" suggestion. I'm not seeing any performance problems, but there's an annoying flicker in all the textboxes.

My original code used the Screen.ActiveControl and Screen.PreviousControl objects, but I got errors when I switched to another application while the form was open. (And I understood why that was).

I guess the best route is, as you said, to code the GotFocus and LostFocus events of every control on the form.
 
Non code alternative interesting?

Using Access 2000+ versions, conditional formatting on the format menu, third option in the first dropdown "Field has focus".

Roy-Vidar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top