我正在尝试在TPageControl上使用TLinkLabel,但找不到任何方法可以使用它的父级背景。

// Image removed because the website doesn't exist any more
// and I can't find it anywhere... Sorry.

如您所见,父选项卡工作表的可爱渐变未保留在链接文本的后面。

我想要在一个流动的文本块中具有多个链接的功能(TLinkLabel提供的功能),并在文本后面显示父级的背景。

TLinkLabel没有ParentBackground属性。我尝试创建一个派生类,将csParentBackground添加到控件样式,但无济于事:
TMyLinkLabel = class (TLinkLabel)
public
  constructor Create(AOwner: TComponent); override;
end;

...

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

有人有主意吗?

最佳答案

纳特,您对ControlStyleTLinkLabel所做的更改就差不多到了。此外,您还需要确保标准Windows静态控件的父级(即TLinkLabel是)正确处理了WM_CTLCOLORSTATIC消息。

VCL具有很好的重定向机制,可让控件自己处理作为通知发送到其父窗口的消息。利用此功能,可以创建一个完全独立的透明链接标签:

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;

关于delphi - TPageControl上的TLinkLabel背景,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/1345316/

10-08 22:42