Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stop Label Caption Flickering

I have a Label that is indicating a file size with

FormatFloat('##.## KB',BytesIn/OneKB);

and it all worked fine when the files were all under about 2MB. Now I am sometimes using files 2GB and up.

FormatFloat('##.##### MB',BytesIn/OneMB);

The Caption is being updated about every 1-KB and the flickering is fierce.

Any way to stop that or minimize it some?

like image 949
user2566616 Avatar asked Jul 10 '13 19:07

user2566616


1 Answers

The Delphi TLabel can indeed be a flickery beast. Many people will recommend double buffering, but I don't like that. It brings other problems. In particular, if you are using themes then double buffering can interfere with the themed rendering.

My trick for dealing with label flicker is to use a TStaticText instead of a TLabel. This is a windowed control, a wrapper around the Windows STATIC control, and in my experience it invariably will not flicker in the scenario where TLabel would.

As others mention, throttling update rate is a sound idea, and is wise irrespective of flickering. There's no need to spend resources updating the UI any faster than the human eye can absorb. For something like download progress you should not really need any more than 5Hz in my view. This may very well be the root cause of your problem, and if throttling update rate solves the problem then you can stick with TLabel.

My answer here has some more general anti-flicker tips: TLabel and TGroupbox Captions Flicker on Resize.

like image 182
David Heffernan Avatar answered Nov 15 '22 04:11

David Heffernan