|
|
![]() | |
|
|
|
To access the contents, click the chapter and section titles.
Visual Basic 6 Black Book
Giving Buttons Access CharactersThe 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 buttons 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 charactersthose 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 buttons 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, weve given the buttons in Figure 7.6 access charactersnote the ampersand in the Caption property in the Properties window.
Setting Button Tab OrderTo make your buttons more accessible from the keyboardespecially if youve got a lot of themyou can use the TabStop, TabIndex, and Default properties. Heres what those properties do:
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.
Disabling ButtonsAnother 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 canyou can disable the button by setting its Enabled property to False when its inappropriate to use that button. For example, weve disabled all the buttons in Figure 7.8. When a button is disabled, it is inaccessible to the user (and it cant accept the focus).
You can also disable buttons at runtime, of course, like this:
Private Sub Command1_Click()
Command1.Enabled = False
End Sub
Showing And Hiding ButtonsIn the last topic, we saw that we can disable buttons using the Enabled property. However, its 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. Heres how to make a button disappear when you click it (and probably startle the user!):
Private Sub Command1_Click()
Command1.Visible = False
End Sub
Adding Tool Tips To ButtonsYour new word processor, SuperDuperTextPro, is a winner, but the User Interface Testing Department has a requestcan you add tool tips to the buttons in your program? Whats a tool tip, you ask? They say that its 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 saybut 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 youre all set. For example, weve added a tool tip to the command button in Figure 7.9.
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 programs users.
|
|
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. |