Click here to Skip to main content
15,922,315 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In windows form,
I am using a combobox (cboProgress) and a ProgressBar (prgProgress)
In the selectedindexchanged event of the combobox (which is populated with numbers from 10 to 100 at interval of 10), I would like to set the value of the progressbar to the selected value of the combobox. And fill the forecolor of the progressbar with a different colour according to the selected number in the combobox.

Question:
Can you please give suggestions on the colours to use for filling the forecolor of the progress bar based on the selected value in the combobox?
This is what I have but I need help in setting the colours please.
Any suggestions on the colours please?

Thanks
C#
private void cboProgress_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cboProgress.SelectedIndex > 0)
            {
                switch (int.Parse(cboProgress.Text))
                {
                    case 10:
                        prgProgress.ForeColor = Color.?;
                        break;
                    case 20:
                        prgProgress.ForeColor = Color.?;
                        break;
                    case 30:
                        prgProgress.ForeColor = Color.?;
                        break;
                    case 40:
                        prgProgress.ForeColor = Color.?;
                        break;
                    case 50:
                        prgProgress.ForeColor = Color.?;
                        break;
                    case 60:
                        prgProgress.ForeColor = Color.?;
                        break;
                    case 70:
                        prgProgress.ForeColor = Color.?;
                        break;
                    case 80:
                        prgProgress.ForeColor = Color.?;
                        break;
                    case 90:
                        prgProgress.ForeColor = Color.?;
                        break;
                    case 100:
                        prgProgress.ForeColor = Color.DarkGreen;
                        break;
                }
                prgProgress.Value = int.Parse(cboProgress.Text);
            }
        }
Posted

If you want to change the colors then I would change them smoothly from red (0) through to green (100)

So as it gets greener, it's more complete.

As red is 0xff0000 and green is 0x00ff00 you could quite easily calculated the values of each given the percentage of completion

That is the R component = 255 *(100 - percentComplete) / 100
The G component = 255 * percentComplete / 100

Doing it that way has the advantage that you can use it with any situation not just the one you describe
 
Share this answer
 
Comments
arkiboys 1-Feb-12 7:44am    
So how can I set the colour of the progressbar based on your suggestion please?
thanks
Michel [mjbohn] 1-Feb-12 10:53am    
Color c = Color.FromArgb(int red, int green, int blue)
Michel [mjbohn] 1-Feb-12 10:54am    
Good idea
My 5
Use Green Color for showing progress
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900