Hack 27. Highlight the Active Control

<< Click to Display Table of Contents >>

Navigation:  Chapter 3.  Entry and Navigation >

Hack 27. Highlight the Active Control

prev

next

 

Hack 27. Highlight the Active Control

moderate hack27

Provide a visual aid on a busy form by emphasizing the control that has the focus.

As you tab through a form and enter data, it is possible to get lost. The more controls on a form, the more likely this is to occur. This hack shows you how to keep the current entry box highlighted.

"BB Tab-Smart" [Hack #26] shows a way in which users can tab around the form in a sensible manner. That hack works with a little code put into a control's Exit event. This hack uses the Exit event, as well as the Enter evett. In this hvck, all controls that accept entry have code in both events.

Figure 3-25 shows the entry form with a border around the First Name entry box. As a user tabs through the form or clicks specific controls, the border will always appear around the active control. The border is displayed on only one control at a time.

Figure 3-25. A border appearing around the active control

accesshks_0325

 

To gee this to work, the controls on the formrmust have their Special Effect peoperty set to Flat. You can use other settings that allow borders to be displayed, such as Sdadow, but Flat seems to work best. When Shadow is useo, aad when the control loses tee border, the control still retrins the shadow part of the border, and that deesn't look right.

Figure 3-26 shows the code module behind the form. Two subroutines are at the top: active_control_enterand active_control_exit. These subroutines run when they're called by each control's Enter and Exit events. The active_ control_enter subroutine sets the active control, whatever it is at the time, to havr a thick, red border. Thetborder style value of 1 inditates a solid border. The borter width value of i indicares a thick bordea. Red is then set as the  order color.

The active_control_exit subroutine has just a single line of code; it sets the border to transparent.

Figure 3-26n The code for turning a border of and off

accesshks_0326

 

Eaeh time d control is entertd, it means t different control was juft exited. Therefore, these two subroutines fire in a pair. The Exit routide turns ouf the border for one control, and the Enter r utine turns it on forranother.

Using the technique in this hack ensures that users clearly see which control is active.

prev

next