我尝试将 VCLStyle 应用于 TLinkLabel。
可悲的是,我无法显示下划线(A 标签的句子)
TLinkLabel.Caption := 'Sma<a>pl</a>e';
我该如何解决这个问题?
解决这个问题,但是标签可能没有出现这个“样本”
procedure TgLinkLabelHook.Paint(Canvas: TCanvas);
var
LDetails: TThemedElementDetails;
ParseStr: String;
DrawRect: TRect;
DC: HDC;
TextSize: TSize;
SaveFont: HFont;
ThemeTextColor: TColor;
begin
ParseStr := ParseLinks;
LDetails := StyleServices.GetElementDetails(tbPushButtonPressed);
DC := GetDC(0);
try
SaveFont := SelectObject(DC, TLinkLabel(Control).Font.Handle);
try
GetTextExtentPoint32(DC, PWideChar(ParseStr), Length(ParseStr), TextSize);
finally
SelectObject(DC, SaveFont);
end;
finally
ReleaseDC(0, DC);
end;
Canvas.Font := TLinkLabel(Control).Font;
Canvas.Font.Style := Canvas.Font.Style + [fsUnderline];
Canvas.Font.Size := TLinkLabel(Control).Font.Size;
if StyleServices.GetElementColor(LDetails, ecBodyTextColor, ThemeTextColor) then
Canvas.Font.Color := ThemeTextColor;
// DrawRect := Rect(0, 0, TextSize.cx, TextSize.cy);
DrawRect := Control.ClientRect;
DrawControlText(Canvas, LDetails, ParseStr, DrawRect, DT_VCENTER or DT_CENTER);
end;
procedure TForm8.FormCreate(Sender: TObject);
begin
TStyleManager.Engine.RegisterStyleHook(TLinkLabel, TgLinkLabelHook);
end;