Welcome to Dream.In.Code
Become a VB.NET Expert!

Join 150,080 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 1,792 people online right now. Registration is fast and FREE... Join Now!




Changing a progress bar's color

 
Reply to this topicStart new topic

Changing a progress bar's color, Can I?

Locke37
2 Jun, 2008 - 11:31 AM
Post #1

Contributor of the Year
Group Icon

Joined: 20 Mar, 2008
Posts: 1,274



Thanked: 57 times
Dream Kudos: 325
My Contributions
I am making a game similar to Final Fantasy (anyone ever heard of it?), and I want there to be gauge like ATB (Active Time Battle), like there were in the later games.

The ATB gauge is a gauge that controls when a character can act, whether it be attacking an enemy, or healing. The gauge is only used in battle.

So can I change the color of a progress bar's...progress? The green part that's fill(ing)? Because the ForeColor property doesn't change that color.
User is offlineProfile CardPM
+Quote Post

RodgerB
RE: Changing A Progress Bar's Color
2 Jun, 2008 - 10:47 PM
Post #2

D.I.C Lover
Group Icon

Joined: 21 Sep, 2007
Posts: 2,166



Thanked: 17 times
Dream Kudos: 2200
Expert In: Dot Net Technologies

My Contributions
AFAIK, you can't change the color of a ProgressBar. I have created a class to do this very thing in a Windows Forms application, you can view the snippet right here on </dream.in.code> (click).

However, please note this snippet doesn't change color (i could have implemented it, but I was more or less demonstrating the concept of health bar creation.

If you'd like to change it's color, I recommend modifying the constructor of the class's signature to allow for types of Brushes, creating a global variable in the class, and then modifying line 60 to point to the global variable you have set from the constructor.

Hope that made sense, and best of luck! smile.gif
User is online!Profile CardPM
+Quote Post

Locke37
RE: Changing A Progress Bar's Color
3 Jun, 2008 - 08:42 AM
Post #3

Contributor of the Year
Group Icon

Joined: 20 Mar, 2008
Posts: 1,274



Thanked: 57 times
Dream Kudos: 325
My Contributions
Heh, makes sense to make a class for it, but uh...What are the rectangle for creating the object and the graphics I am supposed to use for the DrawBar() function?

This post has been edited by Locke37: 3 Jun, 2008 - 08:45 AM
User is offlineProfile CardPM
+Quote Post

Jayman
RE: Changing A Progress Bar's Color
3 Jun, 2008 - 10:03 AM
Post #4

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 7,319



Thanked: 66 times
Dream Kudos: 500
Expert In: Everything

My Contributions
Actually, you don't need to go through all that trouble.

You are correct that you will use the ForeColor property to change the color. However, you must first disable "XP Visual Styles". XP Visual Styles will override a lot of controls to provide a consistent XP experience.

You can find this in your Project Menu -> <Your Project Name> Properties and then deselect the checkbox labeled "Enable XP Visual Styles".

Keep in mind that all the styles will now default to windows 2000 styles, but you can now control the ProgressBar color.


Attached thumbnail(s)
Attached Image
User is offlineProfile CardPM
+Quote Post

Locke37
RE: Changing A Progress Bar's Color
3 Jun, 2008 - 02:04 PM
Post #5

Contributor of the Year
Group Icon

Joined: 20 Mar, 2008
Posts: 1,274



Thanked: 57 times
Dream Kudos: 325
My Contributions
Hm, it worked, and yeah there's the look and feel of Windows 2000. Is there a way to keep it Vista/XP look and feel and having the same effect, or am I just wishing?
User is offlineProfile CardPM
+Quote Post

RodgerB
RE: Changing A Progress Bar's Color
3 Jun, 2008 - 02:04 PM
Post #6

D.I.C Lover
Group Icon

Joined: 21 Sep, 2007
Posts: 2,166



Thanked: 17 times
Dream Kudos: 2200
Expert In: Dot Net Technologies

My Contributions
QUOTE(Locke37 @ 4 Jun, 2008 - 02:42 AM) *

Heh, makes sense to make a class for it, but uh...What are the rectangle for creating the object and the graphics I am supposed to use for the DrawBar() function?


The Rectangle is used to tell the object where it is supposed to be drawn, and how long the health bar's length and width will be.

The GraphicsToUse option is the Graphics it will be drawing on. For example, if you used Me.CreateCraphics in the constructor, it should (hypothetically, not tested) draw the health bar on the form.

I've got school now.. damn. Also jayman, that was a pretty neat way of doing it. icon_up.gif
User is online!Profile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/8/09 11:29PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month