Saturday, August 20, 2005

Progress bars everywhere you look
I've created Visual FoxPro progress bars before (who among us hasn't right?). The last time I developed one, I posted it over in the download section of Universal Thread. It is a COM server progress bar that allows progress indication to smoothly continue even when Visual FoxPro is busy churning away on a single line of code. But in today's project, I set out to create a simpler progress bar that could be placed in a container (form or whatever).

Another progress bar class

I wanted this progress bar to look really professional. I also wanted it to handle being resized to any length or width by the developer during design. I then wanted it to either do a solid bar or create individual blocks like we see in the standard Windows XP progress bar and I wanted it to have the ability to show the percentage complete with a label that would change color as the progress bar went over the top of it (so at 50%, half of the 50% is one color and the other half another). Finally it had to be able to display different colors (green as in Windows XP, as well as red and blue). These are all features I've seen in other progress bars, and felt that Visual FoxPro could use one too.

Progressbar properties of note

barcolor = The color you want the progress bar to be: 1 = Red, 2 = Green, 3 = Blue (defaults to 2)
min = The value to be considered 0% (defaults to 0)
max = The value to be considered 100% (defaults to 100)
percentage = The percentage complete based on the current value assigned (defaults to 0)
showpercentage = Whether the percentage should be displayed to the user (defaults to .F.; best used when solidbar is .T.)
solidbar = Whether progress bar should be shown as a solid as opposed to blocks (defaults to .F.)
value = The current value of the progress (defaults to 0; should fall within the min and max range)

Other development notes
The gradient look of the progress bar was created by dynamically adding lines of varying degrees of color. The percentage showing through the progress bar was facilitated by setting the drawmode property of the lines to 14 - Merge Pen Not.

Download the project
You can either run the progressbarex.exe or you can open the project and run the example.scx. Everything is included in the download. Here is the download link and a screen shot of the included example...

Download ProgressbarEx Example and Source (26 KB approx.)

Saturday, August 20, 2005 12:42:40 PM (Central Daylight Time, UTC-05:00)  #    Comments [12]
Sunday, August 21, 2005 1:21:18 PM (Central Daylight Time, UTC-05:00)
It's because of stuff like this that I make your blog the first one to visit every single day! Great work on your VFP controls and code.
Mike
Sunday, August 21, 2005 2:03:12 PM (Central Daylight Time, UTC-05:00)
Hi Mike,

I'm glad you are finding the blog entries useful. Thank you for stopping by and for the positive feedback.
Tuesday, September 13, 2005 6:00:30 PM (Central Daylight Time, UTC-05:00)
Thanks for sharing this code Craig it's great. Is there anyway to use XP Themes colors for the ProgressBar, or any color that is used in Windows Control Panel.
Tuesday, September 13, 2005 11:09:14 PM (Central Daylight Time, UTC-05:00)
Hi Craig, one more question I'm having problems when the max property is really big for example 25000, the progressbar won't display the color only the label will show. Any idea?

Thanks

Luis
Saturday, October 01, 2005 8:24:06 AM (Central Daylight Time, UTC-05:00)
Hi Luis,

Yes, there are ways to get the system colors as well as some of the theme information (though bear in mind that themes usually use gradients which are a combination of a bunch of colors). There should be some information out on the forums (UT, Tek-Tips, Foxite, etc.) about doing this. A way that I can think of off the top of my head is to use the Point method of the _screen or use an API call to get the titlebar color of active form before bringing up the progressbar and use that value in the code (you'd have to modify the routines in the progressbar though). But this seems like a hack to me, and wouldn't work if your app didn't have a form up at the time the progressbar was needed. So perhaps it is better to poll the system settings somehow. I don't have the code for that in my head, but I am sure it's been spoken about somewhere out on the forums. If you figure out how to do it, be sure to post back here with the solution or email it to me and I'll include it.

As to the bug: Can you send me some code that reproduces what you are seeing? Either post it here or feel free to email it to me and I'll find out what is happening.
Monday, December 05, 2005 3:16:19 PM (Central Standard Time, UTC-06:00)
Simply try it with a big value for Max property. By the way did you see my email messagge? I have some commercial classes I will love to nclude som of them in SednaX, Can you help me?
Monday, December 05, 2005 10:35:59 PM (Central Standard Time, UTC-06:00)
Thanks Craig !!

You can find the Spanish version of this article at (Puede encontrar la versión en Español de este artículo en:)

http://www.portalfox.com/modules.php?op=modload&name=Sections&file=index&req=viewarticle&artid=96

Regards / Saludos,

Ana
www.amby.net
www.PortalFox.com
Tuesday, January 03, 2006 10:51:23 PM (Central Standard Time, UTC-06:00)
I have problems with vfp 8.0 the first control (red) give my problems, I' delete him and work (have Windows XP)
Daniel Salazar
Thursday, June 08, 2006 6:24:15 PM (Central Daylight Time, UTC-05:00)
Hi Craig,

The progressbar class is good. However, it uses ICASE() which is not available in VFP 8.0 or earlier. You may like to modify the class so that it may used in the earlier versions of VFP.
Ravi
Wednesday, May 09, 2007 1:14:00 PM (Central Daylight Time, UTC-05:00)
Hello, i'm trying to use the progress bar to scan a cursor. For exemple : the cursor has 300 records and i want the progress bar to be divided into 300 pieces. I'm using follwing code bur the progress stops at 33,33%... Any idea what i'm doing wrong ?

thisform.Progressbar.Value = 0
thisform.Progressbar.Min = 0
thisform.Progressbar.Max = 300
thisform.Progressbar.Percentage = 100 && total is 100% ?

FOR lnI = 0 TO 300 && =cursor-scan
thisform.Progressbar.Value = lnI
ENDFOR
Tim Delmoitié
Thursday, November 01, 2007 7:18:38 AM (Central Daylight Time, UTC-05:00)
That's great!!
I have never found a VFP progress bar like your, so beautiful~~~
Monday, November 05, 2007 9:30:30 PM (Central Standard Time, UTC-06:00)
Thanks for sharing this.
It's a fine progress beside other progressbars...
Maci Flaviu
Name
E-mail
(will show your gravatar icon)
Home page

Comment (Some html is allowed: a@href@title, b, blockquote@cite, em, i, strike, strong, sub, super, u)  

Enter the code shown (prevents robots):


 

Archive

<August 2008>
SunMonTueWedThuFriSat
272829303112
3456789
10111213141516
17181920212223
24252627282930
31123456