TLinkLabel background on a TPageControl

delphi, delphi-2009

Solution

Nat, you are nearly there with your changes to the `ControlStyle` of the `TLinkLabel`. What you have to do in addition is to make sure that the parent of the standard Windows static control (that's what the `TLinkLabel` is) handles the `WM_CTLCOLORSTATIC` message correctly.

The VCL has a nice redirection mechanism to let controls handle messages that are sent as notifications to their parent windows for themselves. Making use of this a completely self-contained transparent link label can be created:

type
  TTransparentLinkLabel = class(TLinkLabel)
  private
    procedure CNCtlColorStatic(var AMsg: TWMCtlColorStatic);
      message CN_CTLCOLORSTATIC;
  public
    constructor Create(AOwner: TComponent); override;
  end;

constructor TTransparentLinkLabel.Create(AOwner: TComponent);
begin
  inherited;
  ControlStyle := ControlStyle - [csOpaque] + [csParentBackground];
end;

procedure TTransparentLinkLabel.CNCtlColorStatic(var AMsg: TWMCtlColorStatic);
begin
  SetBkMode(AMsg.ChildDC, TRANSPARENT);
  AMsg.Result := GetStockObject(NULL_BRUSH);
end;

Problem

I am trying to use a TLinkLabel on a TPageControl, and I can't find a way to make it use it's parent's background. ``` // Image removed because the website doesn't exist any more // and I can't find it anywhere... Sorry. ``` As you can see, the parent tab sheet's lovely gradient is not preserved behind the link text. I would like the functionality of having multiple links in a flowing block of text (the functionality that TLinkLabel provides) and have the background of the parent showing behind the text. TLinkLabel does not have a ParentBackground property. I have tried creating a derived class that adds csParentBackground to the control style, to no avail: ``` TMyLinkLabel = class (TLinkLabel) public constructor Create(AOwner: TComponent); override; end; ... constructor TMyLinkLabel.Create(AOwner: TComponent); begin inherited; ControlStyle := ControlStyle - [csOpaque] + [csParentBackground] end; ``` Anyone have any ideas?

Original source