Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do i apply to VCLStyle for TLinkLabel

I tried to apply VCLStyle for TLinkLabel.

Sadly, I can not display underline(sentece of A Tag)

TLinkLabel.Caption := 'Sma<a>pl</a>e';

How do I solved this ?

To solve this problem, but a tag is not appeared likely this "Sample" enter image description here

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;
like image 602
JH Jang Avatar asked Jun 08 '12 08:06

JH Jang


1 Answers

How to render a label text based on canvas font settings you used:

Use the TCustomStyleServices.DrawText function:

StyleServices.DrawText(Canvas.Handle, LDetails, ParseStr, DrawRect, DT_VCENTER or DT_CENTER, Canvas.Font.Color);

instead of TStyleManager.DrawControlText. This function uses the default control font settings, so it simply ignores the settings you've done. On its first line it takes the font from the assigned control, what set the canvas font to the default control's font:

Canvas.Font := TWinControlClass(Control).Font;

About your intention:

Note, that it's not possible to use custom colors for label links because they are rendered by the system. There are only two workarounds to change them, either you can set the system colors used for the link font rendering or parse and render the label caption completely by your own, what makes TLinkLabel usage useless.

like image 98
TLama Avatar answered Sep 19 '22 17:09

TLama