更新Windows窗体中的进度条

本文关键字:Windows 窗体 更新 | 更新日期: 2023-09-27 18:08:09

基本上我试图让我的进度条出现在不同的水平和颜色,取决于返回的值,但是我的2个进度条总是看起来一样,即使它们在不同的值。而且颜色也不会更新。

 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;
            }

更新Windows窗体中的进度条

禁用视觉样式,并在颜色更改后更新布局就足够了。