Resizing Controls

Started by JR Heathcote, February 05, 2006, 05:22:36 PM

Previous topic - Next topic

JR Heathcote

I have a form where the controls are resized/relocated as the form is resized.  The resize code is working OK, but what tricks does one employ to reduce or eliminate flicker when controls are moved?

TIA

Roger Garstang

Turn off the Redraw Class Styles, only paint areas once (The normal Erase Background then draw text/control causes the area occupied by it to be drawn twice- once on erase and once on draw...try to find ways to draw what is needed in one operation or compose "off-screen" and transfer finish product [Double Buffer]).  Along with painting once...I've found in some of my resize/move code that pieces can get in the way of each other or move wrong/noticable, so use DeferWindowPos and its related Begin/End Functions.  This then does all the drawing in the background and redraws the window in one command when done.

JR Heathcote

Thanks, will give it a try.

TechSupport

I think that DeferWindowPos is the best general purpose solution for resizing flicker. Like Roger said, the actual redraw only happens once which will look much more pleasing visually.

There are some controls that will always flicker regardless of what you do. For example, I have yet to find a way to prevent a Tab Control from flickering when it is resized. Nothing short of doing a complete ownerdraw  implementation seems to work (and I have searched a lot on google for equivalent ideas in C/C++ or VisualBasic - no luck).

TechSupport

Oh, here is one that I forgot.... Make sure that the WS_CLIPCHILDREN and WS_CLIPSIBLINGS styles are enabled for your Form (I don't think they are by default). This will clip the redraw so the area under your controls are not drawn and then the control drawn on top of it (causing flicker).

Roger Garstang

Sometimes WS_CLIPSIBLINGS gives problems in XP with Frames.  Usually when the Balloon Tips popup to do with letters in a number textbox or caps lock on in a password box, etc.  Frames sometimes dissappear.