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!

Change color of ProgressBar. 1

Status
Not open for further replies.

MasterRacker

New member
Oct 13, 1999
3,343
0
0
US
.NET does not appear to directly support changing the color of a progress bar. In another forum a suggestion was made to "try and post PBM_SETBARCOLOR or PBM_SETBKCOLOR to the progress bar window" via the COntrol.Handle property.

Can anyone provide more assistance with the syntax for this type of operation?

[purple]Jeff
It's never too early to begin preparing for [/purple]International Talk Like a Pirate Day
 
Please let me know if anyone knows how to change the style to continuous too instead of the segmented style!
 
Here is the code where the bkcolor is set to green and the progess bar is black.
Code:
using System.Runtime.InteropServices;
//..
private const Int32 WM_USER = 0x0400;
private const Int32 CCM_FIRST=0x2000;
private const Int32 PBM_SETBARCOLOR = WM_USER +9;
private const Int32 PBM_SETBKCOLOR = CCM_FIRST +1;

public System.Windows.Forms.ProgressBar progress = new System.Windows.Forms.ProgressBar();
//..        
[DllImport("user32.dll", CharSet=CharSet.Auto)]
private static extern bool SendMessage(IntPtr hWnd, Int32 msg, Int32 wParam, Int32 lParam);

//..
private void TestProgressBar1(int num)
{
	this.progress.Minimum = 1;
	this.progress.Maximum = num;
	this.progress.Value = 1;
	this.progress.Step = 1;
	SendMessage(this.progress.Handle,PBM_SETBARCOLOR,0, 0x78FF0000);
	SendMessage(this.progress.Handle,PBM_SETBKCOLOR,0, 0x7800FF00);
	// Loop through .
	for (int x = 1; x <= num; x++)
	{
		this.progress.PerformStep();
		System.Threading.Thread.Sleep(1000);

	}
}

private void button1_Click(object sender, System.EventArgs e)
{
	TestProgressBar1(10);
}
obislavu
 
Thanks. I will play with this as soon as I get a chance.

In the SendMessage call, I am guessing the last hex parameter is the color? If so, can you point me to some documentation on how that's encoded? Is it CMYK or something different?

[purple]Jeff
It's never too early to begin preparing for [/purple]International Talk Like a Pirate Day
 
OK, After playing a little, I see those are not the colors.

Unfortunately, at this point of my life, Interop services are still over my head. I've been digging through MSDN but haven't found anything useful yet. Any insight on how to set specific colors would be appreciated.

[purple]Jeff
It's never too early to begin preparing for [/purple]International Talk Like a Pirate Day
 
The last argument is a COLORREF, which has it's hexadecimal form as: 0x00bbggrr where bb is blue value, gg is the green value, and rr is the red value.

Obislavu -- where does the "78" come in, in the hi byte of the hi word?

Chip H.


____________________________________________________________________
Click here to learn Ways to help with Tsunami Relief
If you want to get the best response to a question, please read FAQ222-2244 first
 
Chip, that's kind of what I thought after some more poking around on MSDN. I figured it's what they call ARGB color. You're telling me it's bgr instead of rgb though.

The 78 has to play some role here because, the background paints black and according to your example it should be blue.

[purple]Jeff
It's never too early to begin preparing for [/purple]International Talk Like a Pirate Day
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top