3

The C # progress bar is not updated accurately in Vista or Windows7

 2 years ago
source link: https://www.codesd.com/item/the-c-progress-bar-is-not-updated-accurately-in-vista-or-windows7.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

The C # progress bar is not updated accurately in Vista or Windows7

advertisements
public partial class Form1 : Form
{
  //....
  private void timer1_Tick(object sender, EventArgs e)
  {
     if (this.progressBar1.Value >= 100)
     {
         this.timer1.Stop();
         this.timer1.Enabled = false;
     }
     else
     {
         this.progressBar1.Value += 10;
         this.label1.Text = Convert.ToString(this.progressBar1.Value);
     }
  }
  //......
}

Here I used a timer to update the progress bar value. It works fine in XP. But in Windows7 or Vista when the progress value is set to say 100 but the graphical progress is not 100!

Searching some threads found that its for animation lag in Vista/Windows7.

How to get rid of this thing?

I don't want to loose the look and feel of Vista/Window7 using:

SetWindowTheme(progressBar1.Handle, " ", " ");


I had the same problem. Fozi's tipps was helping me. The solution from Samir will work fine unless the maximum (100%). To make this work also for 100% the maximum must be increased before. The following worked fine for me.

if (NewValue < progressBar.Maximum)
{
  progressBar.Value = NewValue + 1;
  progressBar.Value--;
}
else
{
  progressBar.Maximum++;
  progressBar.Value = progressBar.Maximum;
  progressBar.Value--;
  progressBar.Maximum--;
}


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK