|
|
![]() | |
|
|
|
To access the contents, click the chapter and section titles.
Visual Basic 6 Black Book
Adding Status Bars To FormsYouve finished your program, and its ready to go to marketbut suddenly the project director calls and asks why theres so many message boxes popping up all the time. You explain that you have to give the user feedback on the file downloading processafter all, downloading the 200MB initialization file from the Internet takes some time, and you like to update the user on the process every time a kilobyte of data has been read. What about using the status bar? the project director asks. Hmm, you thinkwhat about using the status bar? The easiest way to put a status bar in a form is to design your program with the Application Wizard, and the result of that process appears earlier in Figure 4.2. However, you can also add status bars to a program yourself with these steps:
The result appears in Figure 4.9now were using status bars in our programs.
Referring To The Current FormYouve written a terrific subroutine to change a forms color to red
Sub ColorWindow(FormToColor As Form)
FormToColor.BackColor = RGB(255, 0, 0)
End Sub
and you want to color all the forms in your project when the user clicks a button. Thats easy to do using the Me keyword, which refers to the current object. Here, for example, is how wed pass the current form to the ColorWindow() subroutine:
Private Sub Command1_Click()
ColorWindow Me
End Sub
That is, Me is an implicit variable, always available, and stands for the current object, which comes in handy when you want to pass the current object to a procedure.
Redrawing Form ContentsYouve written some code to draw an x across a form like this:
Private Sub Command1_Click()
Line (0, 0)-(ScaleWidth, ScaleHeight)
Line (0, ScaleHeight)-(ScaleWidth, 0)
End Sub
You try it out and it looks perfectbut then the boss walks past and you minimize your program for a second to go back to that word-processing program so youll look busy. When you maximize the x program again, the x is gonewhat happened? One of the biggest headaches for Windows programmers is refreshing the window when required, because that involves redrawing the entire forms contents. To make matters worse, this is a common occurrence, because in Windows, the user is always covering and uncovering windows, minimizing and maximizing them, and changing their size, all of which means that your program has to keep redrawing itself. In C or C++ programs, you have to write all the redrawing code yourself; fortunately, there is an easy fix in Visual Basic (and thats one of the things that made Visual Basic so popular in the first place)you just use the AutoReDraw property. Youve probably already used the AutoReDraw property, but we include it here for reference. When you set this property to True, as shown in Figure 4.10, the graphics displayed in the form are stored and redisplayed when needed. All the window refreshes are done for you.
Now when you minimize and then maximize your x program, the x reappears as it should. Problem solved! Setting Control Tab OrderAnother call from the Testing Department. Theyve been going over your program with a fine-tooth comb and asking about the keyboard interface. What does that mean? you ask. They explain that theoretically, according to Microsoft, users should be able to run all Windows programs with the keyboard alone. But that was archaic years ago, you say. Add it to your program, they say. In Visual Basic, you can make controls accessible to the keyboard by setting their tab order. The user can move around from control to control, highlighting the currently selected control, using the Tab key. But its up to you to set the order in which the focus moves from control to control, and even whether or not a control can be reached with the Tab key. To set the tab order of the controls in your program, follow these steps:
Thats all it takesnow youre giving your program a keyboard interface.
|
|
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. |