Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6386239
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:59:57+00:00 2026-05-25T02:59:57+00:00

I have inherited a control from TPanel and in the Paint event handler, I

  • 0

I have inherited a control from TPanel and in the Paint event handler, I have drawn the entire client rect using a gradient. This works perfectly fine until the user resizes.
When the panel is resized, the panel component flickers too much.

How can i avoid this flicker. I saw the gradients in MS office 2007, even if we resize the client area, there will not be a flicker. Please enlighten me on this.

Thanks in anticipation

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T02:59:58+00:00Added an answer on May 25, 2026 at 2:59 am

    You may want to look at this question How to eliminate the flicker on the right edge of TPaintBox (for example when resizing)

    Good overview of options to avoid flicker and also for TPanel.

    Edit :
    I made a quick test in my Delphi XE version on windows 7.

    With this code I cannot reproduce any flicker.
    The inherited Paint is removed and the Paint routine is quite fast.

    If you still can see flicker, the proposal from Simon can be implemented, but better keep the bitmap created for the lifetime of the component itself.

    unit MainForm;
    
    interface
    
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, ExtCtrls;
    
    type
      TGradientPanel = class(TPanel)
      protected
        procedure Paint; override;
      public
        constructor Create(AOwner: TComponent); override;
      end;
    
    type
      TForm1 = class(TForm)
        procedure FormCreate(Sender: TObject);
      private
        { Private declarations }
        sPanel : TGradientPanel;
      public
        { Public declarations }
     end;
    
    var
      Form1: TForm1;
    
    implementation
    
    {$R *.dfm}
    
    Uses Math;
    
     procedure GradVertical(Canvas:TCanvas; Rect:TRect; FromColor, ToColor:TColor) ;
     var
       Y:integer;
       dr,dg,db:Extended;
       C1,C2:TColor;
       r1,r2,g1,g2,b1,b2:Byte;
       R,G,B:Byte;
       cnt:Integer;
     begin
        C1 := FromColor;
        R1 := GetRValue(C1) ;
        G1 := GetGValue(C1) ;
        B1 := GetBValue(C1) ;
    
        C2 := ToColor;
        R2 := GetRValue(C2) ;
        G2 := GetGValue(C2) ;
        B2 := GetBValue(C2) ;
    
        dr := (R2-R1) / Rect.Bottom-Rect.Top;
        dg := (G2-G1) / Rect.Bottom-Rect.Top;
        db := (B2-B1) / Rect.Bottom-Rect.Top;
    
        cnt := 0;
        for Y := Rect.Top to Rect.Bottom-1 do
        begin
           R := R1+Ceil(dr*cnt) ;
           G := G1+Ceil(dg*cnt) ;
           B := B1+Ceil(db*cnt) ;
    
           Canvas.Pen.Color := RGB(R,G,B) ;
           Canvas.MoveTo(Rect.Left,Y) ;
           Canvas.LineTo(Rect.Right,Y) ;
           Inc(cnt) ;
        end;
     end;
    
    
    constructor TGradientPanel.Create(AOwner: TComponent);
    begin
      inherited Create(AOwner);
      Self.ParentBackground := FALSE;
    end;
    
    procedure TGradientPanel.Paint;
    var
      rect : TRect;
    begin
      //inherited;  // Avoid any inherited paint actions as they may clear the panel background
      rect := GetClientRect;
      GradVertical( Self.Canvas, rect, clBlue, clRed);
    end;
    
    procedure TForm1.FormCreate(Sender: TObject);
    begin
      sPanel := TGradientPanel.Create( Self);
      sPanel.Parent := Self;
      sPanel.Top := 10;
      sPanel.Left := 10;
      sPanel.Width := 300;
      sPanel.Height := 300;
      sPanel.Anchors := [akLeft,akRight,akTop,akBottom];
      sPanel.Enabled := TRUE;
      sPanel.Visible := TRUE;
    end;
    
    end.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a custom control inherited from RichTextBox. This control has the ability to
I have inherited from TGroupBox of the Delphi native control and overriden its Paint
I have a custom control that inherits from .NET's CompositeControl class. This control overrides
I have a WinForms control inherited from TreeView and I want it to automatically
I have developed a server control inherited from WebControl that wraps any number of
I'm developing a Asp.net server control (inherited from DataBoundControl) and I have just one
We have developed a custom control in monotouch (inherited from UITextField, but that shouldn't
I have a base user control (inherited from System.Web.UI.UserControl ) public delegate void MyEventHandler(object
I have a WPF Custom Control inherited from Button. How do I programatically get
I have a custom control of class DottedCanvas inherited from Canvas, which contains some

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.