Windows – How to make TProgressBar stop lagging

delphidelphi-2009windows-vista

I've got an app that runs a long set of operations, and I'm trying to use a TProgressBar to keep track of what's going on. I set a number of steps, and call .StepIt to increment the progress bar.

Problem is, it doesn't keep up very well. Instead of jumping directly to the correct position, it seems to like to slide gradually up to it. That's all well and good if it's eye candy you're after, but when I'm trying to get an accurate representation of my routine's progress, this makes it appear to be constantly lagging behind the true status. How can I turn that "feature" off?

I only notice this happening under Windows Vista. Not sure if it's also going on on XP or not, because when I test it on XP, the process goes a lot faster and it's over too quickly. 😛 But this may or may not be Vista-specific. Either way, it's driving me nuts. Does anyone know how to fix it?

Best Answer

I ran into exactly the same problem a while ago. After searching Google for a long time, I found that it is a Vista-specific problem. It seems to boil down to this: Microsoft added fancy animations to the progress bar control in Vista (i.e., the moving 'highlight'). To make updates more smooth, they implemented some sort of 'lagging' in the repaint of the control --- and this basically screws the whole progress bar control. Rather annoying, I'd say, especially since there doesn't seem to be a decent solution.

See for more details the replies by Arvid Winkelsdorf to this Embarcadero Discussion Forum post:

It's the same for VB, C++ and C# somehow as the problem lies in the Vista drawing of the new animated ProgressBars. To provide a smoother visual feedback drawing is delayed when moving forward. Your application cannot be sure that 100% will be reached at any given time.

By setting the position back to a smaller value, the ProgressBar drawing is forced to jump back. No delay in getting to a position smaller than the current. So you'll have nearly 100% immediately. Afterwards set to the maximum and you'll have exactly 100%.

[...]

There is a similar glitch when using the new Vista ProgressBar Styles like PB Paused or PB Error. If the bar is still moving (MS part) and your app sets the color to paused by SendMessage (like in D2009) the message will be ignored by the ProgressBar.

Related Topic