0
基本上我試圖讓我的進度條出現在不同的級別和顏色,這取決於返回的值,但是我的2個進度條總是看起來一樣,即使它們在不同的價值。此外,顏色也不更新。更新Windows窗體中的進度條
double DFuelLvl = client.GetTankAmounts("Diesel");
double PFuelLvl = client.GetTankAmounts("Unleaded");
if (DFuelLvl < 300)
{
DieselBar.Value = 10;
DieselBar.ForeColor = Color.Red;
DieselBar.Style = System.Windows.Forms.ProgressBarStyle.Continuous;
}
else if(DFuelLvl > 300 && DFuelLvl< 500)
{
DieselBar.Value = 35;
DieselBar.ForeColor = Color.Orange;
DieselBar.Style = System.Windows.Forms.ProgressBarStyle.Continuous;
}
else if (DFuelLvl > 500 && DFuelLvl < 850)
{
DieselBar.Value = 75;
DieselBar.ForeColor = Color.Green;
DieselBar.Style = System.Windows.Forms.ProgressBarStyle.Continuous;
}
else
{
DieselBar.Value = 100;
DieselBar.ForeColor = Color.Blue;
DieselBar.Style = System.Windows.Forms.ProgressBarStyle.Continuous;
}
if (PFuelLvl < 300)
{
Petrolbar.Value = 10;
Petrolbar.ForeColor = Color.Red;
Petrolbar.Style = System.Windows.Forms.ProgressBarStyle.Continuous;
}
else if (PFuelLvl > 300 && DFuelLvl < 500)
{
Petrolbar.Value = 35;
Petrolbar.ForeColor = Color.Orange;
}
else if (PFuelLvl > 500 && DFuelLvl < 850)
{
Petrolbar.Value = 75;
Petrolbar.ForeColor = Color.Green;
}
else
{
Petrolbar.Value = 100;
Petrolbar.ForeColor = Color.Blue;
}
'else if(PFuelLvl> 300 && DFuelLvl <500)'?它不應該是'else if(PFuelLvl> 300 && PFuelLvl <500)'? – 2013-04-08 16:42:13
Doh!是的,謝謝,但仍然顏色不會改變,很奇怪 – 2013-04-08 17:05:28
你可以嘗試updatelayout .... PFuelLvl.Updatelayout() – 2013-04-08 17:06:51