Sometimes you want to change the color of progress bar in c# windows application, you can use the win32 library to do this.
The first thing you should create a new windows forms application project, then drag three progress bar controls from your visual studio toolbox to your winform.
Next you can layout your UI as shown below to learn how to change progress bar color in c# windows application.

Create a new class with the name ProgressBarColor to help you change progress bar style in c# then modify your code as the following.
using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace AppSource
{
public static class ProgressBarColor
{
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]
static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr w, IntPtr l);
public static void SetState(this ProgressBar p, int state)
{
SendMessage(p.Handle, 1040, (IntPtr)state, IntPtr.Zero);
}
}
}
The DllImportAttribute attribute helps you call a function exported from an unmanaged DLL. As a minimum requirement, you must provide the name of the DLL containing the entry point.
Add a Form_Load event handler to your windows forms application.
private void Form1_Load(object sender, EventArgs e)
{
ProgressBarColor.SetState(progressBar1, 2);
ProgressBarColor.SetState(progressBar2, 1);
ProgressBarColor.SetState(progressBar3, 3);
}
Next, add the click event handler to your Color button, then add the code to handle your button click event as shown below.
private void btnChangeColor_Click(object sender, EventArgs e)
{
for (int i = 1; i <= 100; i++)
{
progressBar1.Value = i;
progressBar2.Value = i;
progressBar3.Value = i;
Thread.Sleep(100);
}
}
To play the demo, you can use Thread.Sleep method to deplay process of your progress bar.

Press F5 to run your application, then click the Color button you can change color of progress bar winform as shown above.