Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Progress bar color

Status
Not open for further replies.

SkennyR

Programmer
Mar 7, 2004
157
0
0
US
Can I change the color of the progress bar that is in Microsoft Windows Common Controls?
I cant seem to get it to change form blue.
Thanks..
 
If guitarzan link didn't help.

Why not use a picture box. I have samples if needed or do a search on google for it.

AccessGuruCarl
Programmers helping programmers
you can't find a better site.
 
I found a link to several...


Here is another really good site....


Here is code example found at
Code:
Create a progress bar from a PictureBox

The following code demonstrates a simple technique for turning a VB PictureBox into a progress bar.

'Purpose   :    Creates a progress bar from a picture box
'Inputs    :    pbProgress              The picture box.
'               lPercentComplete        The percentage complete of the progress bar.
'               [lBackColor]            The backcolor of the progress bar (default uses system backcolor).
'               [lForeColor]            The forecolor of the progress bar (default uses blue).
'Outputs   :    Returns 0 on success, else returns an error code
'Notes     :    Example usuage:
'               DrawProgressBar Picture1, 10  'Draws the progress bar 10% complete

Function DrawProgressBar(pbProgress As PictureBox, lPercentComplete As Long, Optional lBackColor As OLE_COLOR = &H8000000F, Optional lForeColor As OLE_COLOR = vbBlue) As Long
    Dim fPercent As Single
    Dim lLenBar As Integer
    
    On Error GoTo ErrFailed
    fPercent = lPercentComplete / 100

    lLenBar = fPercent * pbProgress.ScaleWidth
    'Fill both sides of the bar (incase a backwards progress bar is required)
    pbProgress.AutoRedraw = True
    pbProgress.BackColor = lBackColor
    pbProgress.ForeColor = lForeColor
    pbProgress.Line (0, 0)-(lLenBar, pbProgress.Height), pbProgress.ForeColor, BF
    pbProgress.Line (lLenBar + 1, 0)-(pbProgress.ScaleWidth, pbProgress.Height), pbProgress.BackColor, BF
    DrawProgressBar = 0
    Exit Function

ErrFailed:
    Debug.Print "Error in DrawProgressBar: " & Err.Description
    Debug.Assert False
    DrawProgressBar = Err.Number
End Function

Anyone one of these should work fine.

AccessGuruCarl
Programmers helping programmers
you can't find a better site.
 
I'd have to say, using the API call is alot cleaner and requires no additional controls to be added to the form.

HarleyQuinn
---------------------------------
The most overlooked advantage to owning a computer is that if they foul up there's no law against wacking them around a little. - Joe Martin

Get the most out of Tek-Tips, read FAQ222-2244 before posting.
 
Thanks for the info AccessGuruCarl, But I need to turn the progress bar both vertical and horizontal, depending on the situation. I have not ever been able to turn a picture box vertical.
HQ, is the API you refer to the one I mentioned in the first post? If not, please elaborate.
I like the one I get from the Microsoft Common Controls, but I cant change the color from blue.
Thanks to everyone, I will check out the links posted..
 
I just tried the code in the link posted by quitarzan.
I think it will do what I want. Thanks a lot from all...
(You too HQ and strongm, even though you guys make me WORK to get there. *whinnnne*.. but making me work seems to make it stick longer.)
BTW, The akprogress bar will let you change the color in the properties box, but when you turn it vertical, the width is very limited.
 
I have not ever been able to turn a picture box vertical.

You don't need to rotate the picturebox.

Just set the FillSyle = 4

You'll need to recode the code displayed so the line prints horizontal instead of vertical.

I'll play around with it tonight if I get I chance.

....

HQ or Strongm...
Were you referring to guitarzan post?
I can't get guitarzan code to work.

I called it like this...
Call SetBarColor(ProgressBar1, 255)
Call SetBackColor(ProgressBar1, 255)

What am I doing wrong or how do I get the 'ProgressBarHwnd' value?

Thanks...



AccessGuruCarl
Programmers helping programmers
you can't find a better site.
 
Another option is to use the SSPanel Control within ThreeD32.OCX(Sheridan 3D Controls), its FloodColor property will do the trick and you can have text eg. n% complete displayed over the completion stripe. ThreeD32.OCX is not installed with VB6 by default but it is on the VB6 installation disks; search them and see the related ReadMe.txt.
 
Try:
Call SetBarColor(ProgressBar1.hwnd, 255)
Call SetBackColor(ProgressBar1.hwnd, 255)

Do you know of any way to rotate a label or textbox?
 
Thanks Skenny,

Realized how do it after posting..

Here is how I did it.

Dim lPBHwnd As Long
lPBHwnd = ProgressBar1.hwnd
Call SetBarColor(lPBHwnd, 255)
Call SetBackColor(lPBHwnd, vbGreen)
Basically the same thing...

Rotate Text or Label....
Can be done with API calls...
Try one of these
This is for Access, but I don't see why it won't work in VB. I'd try this one first!
Text At Any Angle

...you asked about textboxes this code is not for
textboxes. That would be tough. May find something on PlanetSourceCode.com

Give it a try and let me know.

AccessGuruCarl
Programmers helping programmers
you can't find a better site.
 
This may do it too, but horizontal only.
Have a Label (or very nearly any control) called LabMeter on a Form

Me.ScaleMode = VbTwips

LabMeter.Left = 100
Labmeter.ForeColor = vbWhite
LabMeter.BackColor = vbRed
LabMeter.Alignment = VbCenter

MeterScale! = (Me.ScaleWidth - 200) / 100 'max stripe width = FormWidth - 200twips

For Progress% = 1 to 100
LabMeter.Width = MeterScale! * Progress%
'optionally
LabMeter.Caption = Progress% & "%"
Next
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top