Hi
how can I change progressbar already on form color by code without create another one
Hi
how can I change progressbar already on form color by code without create another one
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Jayraj ChhayaPosted Dec 19, 2024, 6:04 AM
Hi Samony Me,
In C#, the default
ProgressBarcontrol does not provide a direct property to change its color. However, you can achieve this by overriding theOnPaintmethod or using a custom control. Below is a simple approach using theProgressBarcontrol with a custom drawing technique.First, you need to create a subclass of
ProgressBarand override theOnPaintmethod to customize the appearance:Then, replace your existing
ProgressBarin the form withCustomProgressBar. You can change the color by modifying theBrushes.Greento any color you prefer. This way, you can dynamically change the color of the progress bar without creating a new instance.To use it, simply instantiate
CustomProgressBarin your form and set its properties as needed.Johnnie BarlowPosted Nov 25, 2024, 2:20 AM
You can change the color of an existing progress bar on a form by setting its
ForeColorproperty in the code. Here's an example in C#:This will change the progress bar's color without creating a new one. Just make sure the color you set is compatible with the background color of the progress bar for good visibility.