2013-04-08 112 views
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; 
      } 
+0

'else if(PFuelLvl> 300 && DFuelLvl <500)'?它不應該是'else if(PFuelLvl> 300 && PFuelLvl <500)'? – 2013-04-08 16:42:13

+0

Doh!是的,謝謝,但仍然顏色不會改變,很奇怪 – 2013-04-08 17:05:28

+0

你可以嘗試updatelayout .... PFuelLvl.Updatelayout() – 2013-04-08 17:06:51

回答

0

禁用視覺樣式並在顏色更改後更新佈局就足夠了。