DelphiFAQ Home Search:

Scroll my control without flicker effect

 

commentsThis article has not been rated yet. After reading, feel free to leave comments and rate it.

(see also: My control flickers when it gets repainted!)

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;

Comments:

 

 

Email address (not necessary):

Rate as
Hide my email when showing my comment.
Please notify me once a day about new comments on this topic.
Please provide a valid email address if you select this option.
 
It seems that you are
from Los Angeles, US .

Info/ Feedback on this

Show city and country
Show country only
Hide my location
You can mark text as 'quoted' by putting [quote] .. [/quote] around it.
Please type in the code:
photo Add a picture:

Please do not post inappropriate pictures. Inappropriate pictures include pictures of minors and nudity. The owner of this web site reserves the right to delete such material.