This is a migrated thread and some comments may be shown as answers.

How to change ProgressBar color?

1 Answer 1897 Views
ProgressBar
This is a migrated thread and some comments may be shown as answers.
Oleg
Top achievements
Rank 1
Oleg asked on 10 Jul 2020, 08:22 AM

I'd like to change progressbar color depending on value, for example:

>50 - red

<=50 - green

 

How to do it in app? 

 

 

1 Answer, 1 is accepted

Sort by
0
Nadya | Tech Support Engineer
Telerik team
answered on 13 Jul 2020, 01:40 PM

Hello, Oleg,

I suppose that you would like to change the color of ProgressBarElement within a custom PropertyGridItem. Please refer to the following code snippet that demonstrates how you can achieve this:

public class CustomPropertyGridValueElement : PropertyGridValueElement
{
    RadProgressBarElement progressBarElement;
    protected override void CreateChildElements()
    {
        base.CreateChildElements();
        progressBarElement = new RadProgressBarElement();
        this.Children.Add(progressBarElement);
    }

    public override void Synchronize()
    {
        PropertyGridItem item = this.VisualItem.Data as PropertyGridItem;

        if (item != null && item.Value != DBNull.Value)
        {
            this.progressBarElement.Value1 = Convert.ToInt16(item.Value);
        }
      
        // color progressbar indicator
        if (Convert.ToInt32(item.Value) >= 50)
        {
            this.progressBarElement.IndicatorElement1.BackColor = Color.Red;
            this.progressBarElement.IndicatorElement1.GradientStyle = GradientStyles.Solid;
        }
        else
        {
            this.progressBarElement.IndicatorElement1.BackColor = Color.Green;
            this.progressBarElement.IndicatorElement1.GradientStyle = GradientStyles.Solid;
        }
    }
}

More information about customizing RadProgressBar you can find here: https://docs.telerik.com/devtools/winforms/controls/track-and-status-controls/progressbar/customizing-appearance/accessing-and-customizing-elements

I hope this helps. Let me know if you need further assistance.

Regards,
Nadya
Progress Telerik

Tags
ProgressBar
Asked by
Oleg
Top achievements
Rank 1
Answers by
Nadya | Tech Support Engineer
Telerik team
Share this question
or