Visual Basic 6 Black Book:Toolbars, Status Bars, Progress Bars, And Coolbars
function GetCookie (name)
{
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen)
{
var j = i + alen;
if (document.cookie.substring(i, j) == arg) {
var end = document.cookie.indexOf (";", j);
if (end == -1)
end = document.cookie.length;
return unescape(document.cookie.substring(j, end));
}
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0) break;
}
return null;
}
var m1='';
var gifstr=GetCookie("UsrType");
if((gifstr!=0 ) && (gifstr!=null)) { m2=gifstr; }
document.write(m1+m2+m3);
Keyword
Title
Author
ISBN
Publisher
Imprint
Brief
Full
Advanced Search
Search Tips
Please Select
-----------
Components
Content Mgt
Certification
Databases
Enterprise Mgt
Fun/Games
Groupware
Hardware
IBM Redbooks
Intranet Dev
Middleware
Multimedia
Networks
OS
Prod Apps
Programming
Security
UI
Web Services
Webmaster
Y2K
-----------
New Titles
-----------
Free Archive
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
function isIE4()
{
return( navigator.appName.indexOf("Microsoft") != -1 && (navigator.appVersion.charAt(0)=='4') );
}
function bookMarkit()
{
var url="http://www.itknowledge.com/PSUser/EWBookMarks.html?url="+window.location+"&isbn=0";
parent.location.href=url;
//var win = window.open(url,"myitk");
//if(!isIE4())
// win.focus();
}
Search this book:
Previous Table of Contents Next
You can also set a status bar panels image at runtime. For example, heres how we set the image in the first panel of a status bar, using the image in a picture box when the user clicks a button (you can also use the LoadPicture function to load images in directly):
Private Sub Command1_Click() StatusBar1.Panels(1).Picture = Picture1.Picture End Sub
TIP: You can even create animation in a status bar panel; just set up a timer and place a succession of images in the panels Picture property.
Handling Panel Clicks Are status bars static controls? Or can they handle events? Status bars certainly can handle events, and the most common are PanelClick and PanelDblClick. The event handler procedures for those events are passed the panel that was clicked, as in this example:
Private Sub StatusBar1_PanelClick(ByVal Panel As ComctlLib.Panel)
End Sub
You can tell which panel was clicked by checking the Panel arguments Index or Key properties. For example, heres how we use the Index property to report to the user which panel was clicked:
Private Sub StatusBar1_PanelClick(ByVal Panel As ComctlLib.Panel) MsgBox "You clicked panel " & Panel.Index End Sub
If youve set the Key properties of the panels in your status bar (the Key property holds a text string), you can set up a Select Case statement to see which panel was clicked and take the appropriate action:
Private Sub StatusBar1_PanelClick(ByVal Panel As ComctlLib.Panel) Select Case Panel.Key Case "Date" Panel.Text = Date$ Case "Time" Panel.Text = Time$ End Select End Sub
Adding New Panels To A Status Bar At Runtime Its easy to add a new status bar panel at runtimejust use the Panels collections Add method. Heres an example where we add a panel to a status bar when the user clicks a command button:
Private Sub Command1_Click() Dim panel5 As Panel Set panel5 = StatusBar1.Panels.Add() Panel5.Text = "Status: OK" End Sub
Creating Simple Status Bars Theres a way of using a status bar without using panels: by making the status bar a simple status bar. How do you make a status bar into a simple status bar? You set its Style property to sbrSimple (which equals 1; the other option is sbrNormal, which equals 0). Simple status bars have only one panel, and you set the text in that panel with the SimpleText property. Heres an example; in this case, we just display the message Status: OK in the simple status bar when the user clicks a button:
Private Sub Command1_Click() StatusBar1.SimpleText = "Status: OK" End Sub
The result of this code appears in Figure 15.24.
Figure 15.24 Using a simple status bar.
TIP: One reason programmers used to use simple status bars was to show the progress of an operation by displaying a succession of dots (or other text) in the status bars single long panel. However, you can use the progress bar control for that these dayssee the next topic in this chapter.
Adding A Progress Bar To A Form The Testing Department is calling again. Why does downloading the 200MB data file your program requires take so long? Well, you explain, the Internet is like that. They ask, but cant you at least show the user what progress the downloading operation is making? You take a look at the Progress Bar Control tool in the Visual Basic toolbox. Sure, you say, no problem.
You can use progress bar controls to show the progress of a time-consuming operation. These controls display a colored band that can grow (or shrink) as time goes on. To add a progress bar to a form, follow these steps:
1. Select the Project|Components menu item. 2. Click the Controls tab in the Components dialog box. 3. Select the Microsoft Windows Common Controls item, and click on OK to close the Components dialog box. This adds the Progress Bar Control tool to the Visual Basic toolbox, as shown in Figure 15.3. 4. To place a progress bar in your form, just add it as you would any control, using the Progress Bar Control tool. 5. Set the progress bars Min (default is 0) and Max (default is 100) properties as desired to match the range of the operation youre reporting on.
Now youve got a new progress bar in your formbut how do you use it? See the next topic.
Using A Progress Bar Now that youve added a progress bar to your program and set its Min and Max properties, how do you actually use it to display data? You use a progress bars Value property (available only at runtime) to specify how much of the progress bar is visible. As you might expect, setting Value to Min means none of the progress bar is visible, and setting it to Max means all of it is. Lets see an example. In this case, well let the user click a button to display a progress bar whose bar lengthens from Min to Max in 10 seconds. Add a progress bar, command button, and a timer control to a form now. Set the timers Interval property to 1000 (in other words, 1000 milliseconds, or 1 second). Well leave the progress bars Min property at 0 and its Max property at 100, the defaults. When the form loads, we disable the timer and set the progress bars Value to 0:
Private Sub Form_Load() Timer1.Enabled = False ProgressBar1.Value = 0 End Sub
When the user clicks the command button, we want to start the progress bar, so we enable the timer. We also set the progress bar back to 0 (even though we did that when the form loads, the user might want to restart the operation, which means he might click the button several times):
Private Sub Command1_Click() ProgressBar1.Value = 0 Timer1.Enabled = True End Sub
Finally, in the Timer event handler, Timer1_Timer, we add a value of 10 to the progress bars Value property every second. We also check if weve filled the progress bar, and if so, disable the timer:
Private Sub Timer1_Timer() ProgressBar1.Value = ProgressBar1.Value + 10 If ProgressBar1.Value >= 100 Then Timer1.Enabled = False End Sub
Thats all we neednow when the user clicks the command button, we start the progress bar in motion, and it goes from 0 to 100 in 10 seconds, as shown in Figure 15.25.