Author: William Gerbert
Scroll my control without flicker effect
Answer:
The easiest way to scroll the elements of a control is to force a complete repaint
of the control. Unfortunately this produces the flicker effect. You may use
InvalidateRect(MyControl.Handle, nil, FALSE);
(important: last parameter = FALSE) to cause a complete redraw without erasing the
background.
The best way to reduce this flickering is to use the ScrollWindow or ScrollWindowEx
Windows API function. Look them up in your Win32.HLP file.
Another source of flickering can be from Windows using two messages to paint:
WM_PAINT and WM_ERASEBKGND.
You may want to intercept all of the WM_ERASEBKGND messages and do all of your
painting, including the background, in response to WM_PAINT messages in the Paint
method:
1 type2 TMyComponent = class(TWinControl)
3 // ..4 protected5 procedure WMEraseBkgnd(varmessage: TWMEraseBkgnd);
6 message WM_ERASEBKGND;
7 // ..8 9 end;
10 11 // ..12 13 procedure TBMyComponent.WMEraseBkgnd(varmessage: TWMEraseBkgnd);
14 begin15 message.Result := 0
16 end;