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
2009-09-21 12:25:03
+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
2009-09-21 13:14:01
+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:
- Disable the property
FullRepaint
on your panels. - Enable the property
DoubleBuffered
on your form. You won't find this property on the object inspector, so putDoubleBuffered := true;
in FormCreate.
Svein Bringsli
2009-09-21 12:33:54
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
2009-09-21 13:15:57
DoubleBuffered basically makes your app useless on Citrix and Terminal Server.
Jeroen Pluimers
2009-09-21 16:24:12
>>> "DoubleBuffered basically makes your app useless on Citrix and Terminal Server"Can you specify why?
Alexander
2009-09-21 17:53:48
@Alexander: See the answers to http://stackoverflow.com/questions/1408664/why-is-doublebuffered-disabled-by-default
mghie
2009-09-21 18:17:21
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
2009-09-21 19:08:07
+1
A:
I've got around this as follows:
- 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.
- 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
2009-09-21 14:12:54
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
2009-09-23 09:11:57
+4
A:
procedure TForm1.WMEnterSizeMove(var Message:TWMMove);
begin
Self.DisableAlign;
end;
procedure TForm1.WMExitSizeMove(var Message:TWMMove);
begin
Self.EnableAlign;
end;
A. Vrbic
2009-09-21 19:54:39
You get nice source code formatting if you indent your code with 4 spaces.
Smasher
2009-09-21 20:36:56
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
2009-09-23 09:08:09
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
2009-09-23 13:41:45