Click Here!
home account info subscribe login search My ITKnowledge FAQ/help site map contact us


 
Brief Full
 Advanced
      Search
 Search Tips
To access the contents, click the chapter and section titles.

Visual Basic 6 Black Book
(Publisher: The Coriolis Group)
Author(s): Steven Holzner
ISBN: 1576102831
Publication Date: 08/01/98

Bookmark It

Search this book:
 
Previous Table of Contents Next


Giving Buttons Access Characters

The Testing Department is on the phone again. Everyone loves your new program, SuperDuperTextPro, but as usual there are “one or two little things.” And, as usual, one of those things is keyboard access. Ideally, they say, the user should be able to use programs entirely from the keyboard, without the mouse at all. Well, you say, the button’s tab order was set correctly (see the next topic). But, they say, what about giving your buttons access characters?

You know you can give menu items access characters—those underlined characters in a menu item that the user can reach with the Alt key. Can you add them to buttons?

Yes, you can, and in the same way as you do with menu items. Just place an ampersand (&) in front of the character in the button’s caption that you want to make into the access character for that button (and make sure that the access character is unique among all the access characters available at one time). As an example, we’ve given the buttons in Figure 7.6 access characters—note the ampersand in the Caption property in the Properties window.


Figure 7.6  Setting access characters.

Setting Button Tab Order

To make your buttons more accessible from the keyboard—especially if you’ve got a lot of them—you can use the TabStop, TabIndex, and Default properties. Here’s what those properties do:

  TabStop indicates if this button can accept the focus when the user tabs to it.
  TabIndex is the index of the current button in the tab order (starts at 0).
  Default is True for one control on a form only; that control will have the focus when the form first appears (by default, so to speak, the default control is the control with TabIndex 0).

When the user presses the Tab key, the focus moves from button to button, ascending through the tab order.

You can arrange the tab order for your buttons with the TabIndex property. For example, in Figure 7.7 the first button, at upper left, has the focus (you can tell because its border is thickened). Pressing the Tab key will move the focus to the next button, and the next, then to the next row, and so on.


Figure 7.7  Using tab-enabled buttons.


TIP:  Another use of tab order is in text-entry forms. If, for example, you have 10 text boxes in a row that need to be filled out, the user can enter text in the first one, press the Tab key to move to the next one, enter text there, press Tab again to move to the next text box, and so on. Thoughtfully setting the tab order in such a case can make text-oriented forms much easier on your users.

Disabling Buttons

Another problem from the Testing Department concerning your program, SuperDuperTextPro. It seems the users are sometimes pressing your Connect To The Internet button twice by mistake, confusing the program and causing crashes. Can you stop that from happening?

Yes, you can—you can disable the button by setting its Enabled property to False when it’s inappropriate to use that button. For example, we’ve disabled all the buttons in Figure 7.8. When a button is disabled, it is inaccessible to the user (and it can’t accept the focus).


Figure 7.8  Disabling buttons in a form.

You can also disable buttons at runtime, of course, like this:

Private Sub Command1_Click()
    Command1.Enabled = False
End Sub


TIP:  If you set a button’s Style property to Graphical (Style = 1), you can set the button’s DisabledPicture property to a picture, such as from an image file. And when the button is disabled, that image will appear in the button. That can be very useful to reinforce the fact that the button is disabled—you might have a big X appear, for example.

Showing And Hiding Buttons

In the last topic, we saw that we can disable buttons using the Enabled property. However, it’s an inefficient use of space (and frustrating to the user) to display a lot of disabled buttons. If you have to disable a lot of buttons, you should hide them.

To make a button disappear, just set its Visible property to False. To make it reappear, set the Visible property to True. You can set this property at either design time or runtime. Here’s how to make a button disappear when you click it (and probably startle the user!):

Private Sub Command1_Click()
    Command1.Visible = False
End Sub


TIP:  If your program shows and hides buttons, you can rearrange the visible buttons to hide any gaps using the buttons’ Move method (the Move method is discussed in “Resizing And Moving Buttons From Code” later in this chapter).

Adding Tool Tips To Buttons

Your new word processor, SuperDuperTextPro, is a winner, but the User Interface Testing Department has a request—can you add tool tips to the buttons in your program? What’s a tool tip, you ask? They say that it’s one of those small yellow boxes with explanatory text that appears when you let the mouse cursor rest above an object on the screen. “Of course I can add those,” you say—but can you really?

Yes you can, using the ToolTipText property for the buttons. You just place the text you want to appear in the tool tip into the ToolTipText property to create a tool tip for the button, and you’re all set. For example, we’ve added a tool tip to the command button in Figure 7.9.


Figure 7.9  A button’s tool tip.

You can also set tool tip text at runtime, using the ToolTipText property this way in code:

Private Sub Command1_Click()
    Command1.ToolTipText = "You already clicked me!"
End Sub

If your buttons change functions as your program runs, changing the buttons’ tool tip text can be very helpful to your program’s users.


Previous Table of Contents Next


Products |  Contact Us |  About Us |  Privacy  |  Ad Info  |  Home

Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc.
All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited.