Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Microsoft: FoxPro FAQ

Tips -N- Tricks

How do I use the StatusBar Active-x Control by DSummZZZ
Posted: 29 Jan 04 (Edited 30 Jan 04)

You want more from a status bar than what comes natively with VFP.
There is a status bar Active-x control, but it isn't the most user friendly, nor is the documentation all that swell.  Par for the Active-x course.  I wanted to use one in an app I'm developing and also, there have been several questions posted in this forum on status bars.  

So if you just want to use a status bar on your form, drop one on there, right click and select 'SBarCtrl Properties'.  Click on Panels and make your panels look how you like.  You can add text, key status (CTRL, CAPS, etc.).  ToolTips, pictures and so on.
Fine.  That's all well and good, but other than keyboard status, folks usually want different messages displayed, or other GUI things.  Programmatically.  That's what this FAQ is about.

For a complete demo form with all the graphics and user interface, go here: http://www.davesummers.net/foxprolinks.htm
Scroll down until you get to 'StatusBar Active-x Demo' and download 'StatusBarDemo.zip'
I saved the path names so it will unzip to a folder named C:\vfp_source\statusbar and the graphics will unzip to C:\vfp_source\statusbar\graphics.  From the IDE, run either the form or the program code.  You will see several buttons, a radio control, a couple spinners, and a text box with the status bar at the bottom.
The buttons run some demo code.  The radio control selects the auto-sizing of the panels (play with that a little, you'll see how it works).  The first spinner selects which panel to work with and the second adjusts the size of the selected panel.  The text box changes the text of the selected panel.

One thing to note on adding the statusbar control, as foxwizard pointed out, is that if the form's windowstate is set to 2, the control will remain at wherever the bottom of the form was at design time.  So if the form runs as maximized, the control could be floating somewhere in the middle of the form.  To cure that, in the form's Init event, add the following line:
Thisform.Mystatusbar1.Width = Thisform.Width

Anyway, on to the FAQ:
1- I added a status bar control, I need more panels.
2- I have panels, I need text.
3- Too many panels
4- I have panels, I need pictures.
5- How about a progress bar?  (Are you serious?)
6- I need CAPS lock, NUM lock, Date and Time.
7- Resize the panels
8- Text and a picture?  No way!

1- I added a status bar control, I need more panels.
This adds a panel to the end of the current panels, and sets its resize property to 200:
WITH Thisform.Mystatusbar1
   .Panels.Add(Thisform.Mystatusbar1.Panels.Count + 1)
   .Panels(Thisform.Mystatusbar1.Panels.Count).Width = 200

If you want to insert a panel at a position in between two others, say add panel #3, you can just specify that position as in:  Thisform.Mystatusbar1.Panels.Add(3)

2- I have panels, I need text.
This code will set the text of the specified panel:
ThisForm.mystatusbar1.Panels(2).Text = 'Test text'

Substitute .spPanelNumber.Value for a specific panel number if you wish.
Here's another example using RECNO():
WITH ThisForm
   .mystatusbar1.Panels(.spPanelNumber.Value).Text = ;
      Alltrim(str(RECNO())) + ' of ' + Alltrim(str(reccount()))

3- Too many panels
To remove a panel, either specify which panel to remove by idnex number.  In this example I use the 'count' property to remove the last in line:
With Thisform.Mystatusbar1

Of course you can once again, use the index number:  Thisform.Mystatusbar1.Panels.Remove(3)

4- I have panels, I need pictures.
After you have created the handle to the picture object using:
    STORE LOADPICTURE(Home() + 'Graphics\TRFFC10A.ICO') TO oGreenLight

You can use that handle to display the picture on the statusbar using:
    Thisform.Mystatusbar1.panels(1).Picture = oGreenLight

5- How about a progress bar?  (Are you serious?)
For a progress bar, I made 13 little bitmaps with progressively longer coloring.  All you do is set the picture to each one of these, and it looks like a real progress bar.  Since I can't post them here for you to use, make your own or use the link to download mine.  I made them about 15 pixels high by about 150 wide.  In the form's Init method, you first create a handle to each of the picture objects:
FOR zzz = 0 TO 12
   STORE 'oBar' + Alltrim(Str(zzz)) TO cNewVar
   PUBLIC (cNewVar)
   STORE LOADPICTURE('Graphics\' + Substr(cNewVar, 2) + '.bmp') TO (cNewVar)

Where the files are name bar0.bmp - bar12.bmp

Then elsewhere in code, set them as the picture:
With Thisform.Mystatusbar1
   .panels(3).Width = 150
   .panels(3).Picture = oBar0
   For zzz = 0 To 12
      obar = 'oBar' + Alltrim(Str(zzz))
      .panels(3).Picture = &obar
   .panels(3).Picture = .null.   &&... no picture when done

6- I need CAPS lock, NUM lock, Date and Time.
These are nothing special to create.  The control takes care of the work for you.  All you have to do is set the 'Style' property to a value greater than 0 (plain text):
1 = Caps, 2 = Num, 3 = Ins, 4 = Scrl, 5 = Time, 6 = Date

This chunk of code adds the panels and sets their type:
STORE Thisform.mystatusbar1.Panels.Count TO nHowMany
For zzz = 1 TO 6
   With Thisform.Mystatusbar1
      .Panels.Add(zzz + nHowMany )
      .Panels(zzz + nHowMany ).Width = IIF(zzz > 4, 70, 40) &&... clock and date need to be wider
      .Panels(zzz + nHowMany ).Style = zzz

7- Resize the panels
To resize the panels, you just give the panel the number of pixels wide you want it to be:
Thisform.Mystatusbar1.Panels(3).Width = 150

Or you can use a textbox or spinner control to resize a panel:
Thisform.Mystatusbar1.Panels(3).Width = Thisform.Text1.value
Thisform.Mystatusbar1.Panels(3).Width = Thisform.Spinner1.value

8- Text and a picture?  No way!
Now just for kicks, let's add text to the picture panel.
After you have created the handle to the picture object using:
    STORE LOADPICTURE(Home() + 'Graphics\TRFFC10A.ICO') TO oGreenLight

You can do this:

Thisform.Mystatusbar1.Panels(1).Width = 300
Thisform.Mystatusbar1.panels(1).Picture = oGreenLight
Thisform.Mystatusbar1.panels(1).Text = "This is the green light"

Again, download the file mentioned above for a full demo and full code, and even better documentation.
Hey, it could be fun!

Back to Microsoft: FoxPro FAQ Index
Back to Microsoft: FoxPro Forum

My Archive

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close