2009. március 4., szerda

Scroll my control without flicker effect


Problem/Question/Abstract:

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:


type
  � TMyComponent = class(TWinControl)
    // ..
    � protected
      ��� procedure WMEraseBkgnd(var message: TWMEraseBkgnd);
    ����� message WM_ERASEBKGND;
    // ..
    �
  end;

  // ..

procedure TBMyComponent.WMEraseBkgnd(var message: TWMEraseBkgnd);
begin
  message.Result := 0
end;

Nincsenek megjegyzések:

Megjegyzés küldése