2

I have a form and paint it with a gradient on a Paint event. Also I have frames on that form. I want that frames will be transparent to see the gradient of the form or to paint the frames with the gradient instead if transparency isn't available.

The form and the frame mustn't flicker :)

Ho to do it? Thanks.

Edited:

As I see, there are flickers for frame's transparency. So the best solution for me now is to override TFrame1.PaintWindow(DC: HDC) and paint a background of the frame with a gradient.

maxfax
  • 4,281
  • 12
  • 74
  • 120
  • 1
    I suggest that you try and apply some of the ideas presented here: http://stackoverflow.com/questions/8058745/tlabel-and-tgroupbox-captions-flicker-on-resize in particular I expect WS_EX_COMPOSITED will help. – David Heffernan Jan 09 '12 at 07:44
  • @David Heffernan, the frame is buggy with WS_EX_COMPOSITED – maxfax Jan 09 '12 at 07:59
  • We can't do anything if the only info you give is "the frame is buggy". My frames work fine. Did you put the style on all controls? What else did you change? – David Heffernan Jan 09 '12 at 08:05
  • I applied the style only for the frame :) Thanks a lot David!!!!!!!!!!!!!!!!!!!!!!!! – maxfax Jan 09 '12 at 08:12

1 Answers1

6

Here is a trick to get transparency in frames, as described here : how-to-make-delphi-tframe-background-transparent.

type
  TMyFrame = class(TFrame)
    procedure CreateParams(var Params: TCreateParams);override;
    procedure PaintWindow(DC: HDC); override;
  public
    constructor Create(AOwner:TComponent);override;
  end;

constructor TMyFrame.Create(AOwner: TComponent);
begin
  inherited;
  Brush.Style := bsClear;
end;

procedure TMyFrame.CreateParams(var Params: TCreateParams);
begin
  inherited;
  Params.ExStyle := Params.ExStyle or WS_EX_TRANSPARENT or WS_EX_COMPOSITED;
end;

procedure TMyFrame.PaintWindow(DC: HDC);
begin
  // Do not remove this comment to keep transparancy
end;

Updated :

David suggested adding WS_EX_COMPOSITED to the style to avoid flicker when resizing. This should be added to all controls.

LU RD
  • 34,438
  • 5
  • 88
  • 296
  • thanks, I've tried it before. Set DoubleBuffered to true for a form and a frame, resize the form -> the frame flickers...it's bad. – maxfax Jan 09 '12 at 07:02
  • Have you tried to set the frame `ParentBackground` property to `false` ? – LU RD Jan 09 '12 at 07:19
  • sure! Does your frame not flicker for you? I have Delphi XE2 – maxfax Jan 09 '12 at 07:31
  • 1
    add WS_EX_COMPOSITED to stop flicker. Best only to do this whilst resizing. I'm sure I posted a comprehensive anti-flicker answer here. – David Heffernan Jan 09 '12 at 07:35
  • 2
    @DavidHeffernan, you mean this : [tlabel-and-tgroupbox-captions-flicker-on-resize](http://stackoverflow.com/questions/8058745/tlabel-and-tgroupbox-captions-flicker-on-resize) – LU RD Jan 09 '12 at 07:40
  • this code flickers in D5/D7 when form is resized. `WS_EX_COMPOSITED` makes it flicker even worst. – kobik Jan 09 '12 at 22:58
  • 1
    @kobik, which OS are you using ? `WS_EX_COMPOSITED` is not handled well in XP. – LU RD Jan 09 '12 at 23:11
  • do a WM_ERASEBKGND and Paint override. – NaN Jun 29 '14 at 20:01