Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to prevent csOpaque child controls from flickering Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
29-Aug-02
Category
VCL-Forms
Language
Delphi 2.x
Views
122
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Tomas Rutkauskas

I have a TPaintBox that I use to draw a representation of the data the user is 
entering. It updates whenever the form is repainted or data is changed. This works 
fine. Using D5, I've noticed that when the user is moving the mouse around causing 
hints to pop up and down, it causes a tremendous amount of flicker. In part, this 
is caused by the fact that I clear the canvas before redrawing. Should I draw to an 
invisible paintbox and then copy to a TImage?

Answer:
1   
2   { Overrides the WM_ERASEBKGND message in TWinControl and TForm to prevent flicker 
3   of csOpaque child controls.
4   Unpublished; (c) 1999, David Best, davebest@usa.net
5   You are free to use this and derived works provided you acknowlege it's source in 
6   your code.}
7   
8   procedure WMEraseBkgndEx(WinControl: TWinControl; var message: TWmEraseBkgnd);
9   var
10    i, Clip, SaveIndex: Integer;
11  begin
12    { Only erase background if we're not doublebuffering or painting to memory }
13    with WinControl do
14      if not DoubleBuffered or (TMessage(message).wParam = TMessage(message).lParam) 
15  then
16      begin
17        SaveIndex := SaveDC(message.DC);
18        Clip := SimpleRegion;
19        if ControlCount > 0 then
20        begin
21          for i := 0 to ControlCount - 1 do
22            if not (Controls[i] is TWinControl) then
23              {child windows already excluded}
24              with Controls[i] do
25              begin
26                if (Visible or (csDesigning in ComponentState) and not
27  								(csNoDesignVisible in ControlStyle))
28                   and (csOpaque in ControlStyle) then
29                begin
30                  Clip := ExcludeClipRect(message.DC, Left, Top, Left +
31  								 Width, Top + Height);
32                  if Clip = NullRegion then
33                    break;
34                end;
35              end;
36        end;
37        if Clip <> NullRegion then
38          FillRect(message.DC, ClientRect, Brush.Handle);
39        RestoreDC(message.DC, SaveIndex);
40      end;
41    message.Result := 1;
42  end;
43  
44  procedure TNoFlickerForm.WMEraseBkGnd(var msg: TWMEraseBkGnd);
45  begin
46    WMEraseBkgndEx(Self, msg);
47  end;


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC