views:

748

answers:

4

When resizing a form with many controls, the form looks bad because of flickering. What are some tips to have a smoother form resizing?

+2  A: 

Try using WM_SETREDRAW (not LockWindowUpdate).

You might also have a look at DeferWindowPos.

Ulrich Gerhardt
+1, both very good pieces of advise in itself. These probably won't help with a complex VCL form using alignment, nested controls and so on, though. `DeferWindowPos()` is worth testing for manual placement in `OnResize` handler.
mghie
+2  A: 

Complex forms are often made up of nested panels, and the repaint process may cause flickering. If this is the case with your project there are two easy solutions that might help:

  1. Disable the property FullRepaint on your panels.
  2. Enable the property DoubleBuffered on your form. You won't find this property on the object inspector, so put DoubleBuffered := true; in FormCreate.
Svein Bringsli
Note that `DoubleBuffered` trades less flicker for slower update speed, an effect that can be noticeable on large screens, where resizing may become "jumpy" with larger window sizes.
mghie
DoubleBuffered basically makes your app useless on Citrix and Terminal Server.
Jeroen Pluimers
>>> "DoubleBuffered basically makes your app useless on Citrix and Terminal Server"Can you specify why?
Alexander
@Alexander: See the answers to http://stackoverflow.com/questions/1408664/why-is-doublebuffered-disabled-by-default
mghie
DoubleBuffered: see http://www.delphi3000.com/articles/article_1537.asp?SK= and http://stackoverflow.com/questions/1444830/does-anyone-know-about-issues-between-citrix-and-delphi-2007-applications-and-p
Jeroen Pluimers
+1  A: 

I've got around this as follows:

  1. In the 'OnResize' event of the form, have a routine to hide all child controls and then start a timer with a tick of about 500ms.
  2. When the timer fires, disable it and then set all child controls to visible.

By playing around with this activity you get a form that goes blank whilst you are sizing it, but then populates itself neatly when you 'let go'.

Bri

Brian Frost
I think you would find that handling the enter/exit size move messages (with the modification noted in my comment above) produces a better user experience because you can at least see the (unsized) form while you resize the window.
frogb
+4  A: 
procedure TForm1.WMEnterSizeMove(var Message:TWMMove);
begin
  Self.DisableAlign;
end;

procedure TForm1.WMExitSizeMove(var Message:TWMMove);
begin
  Self.EnableAlign;
end;
A. Vrbic
You get nice source code formatting if you indent your code with 4 spaces.
Smasher
That's fine at preventing flicker, but it also seems to prevent alignment altogether. I added an Invalidate call after enabling alignment: not perfect, because you cannot see exactly what effect the form resize is going to have, but at least it eliminates all flicker on a complex multi-panel form.
frogb
procedure WMEnterSizeMove(var Message:TWMMove); message WM_ENTERSIZEMOVE; procedure WMExitSizeMove(var Message:TWMMove); message WM_EXITSIZEMOVE;does not fire the aproporiate events. Actually forgot to mention it is a frame and not a form but I guessed that it would have been the same.
Aldo