TLinkLabel背景上的一个TPageControl [英] TLinkLabel background on a TPageControl
问题描述
我正在尝试在TPageControl上使用TLinkLabel,我找不到一种方法来使其成为父母的背景。
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.
我希望在流动的文本块(TLinkLabel提供的功能)和中具有多个链接的功能具有父母显示在文本后面。
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没有ParentBackground属性。我已经尝试创建一个派生类,将csParentBackground添加到控件样式,无效:
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;
任何人都有任何想法?
推荐答案
Nat,你几乎在那里你对 ControlStyle
对 TLinkLabel
。另外你还要做的是确保标准的Windows静态控件(这就是 TLinkLabel
的父级)处理 WM_CTLCOLORSTATIC
消息正确。
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.
VCL有一个很好的重定向机制,让控件处理作为通知发送到其父窗口的消息。使用这个可以创建一个完全独立的透明链接标签:
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;
这篇关于TLinkLabel背景上的一个TPageControl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!