How can I access VCLStyle for TLinkLabel

I tried applying VCLStyle to TLinkLabel.

Sorry, I canโ€™t display the underscore (sentece of Tag)

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

How did I solve this?

To solve this problem, but the tag does not seem likely, this "example" 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; 
+6
source share
1 answer

How to visualize label text based on the canvas font settings you use:

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 your settings. On the first line, it takes the font from the assigned control, which sets the canvas font to the default control font:

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

About your intention:

Please note that it is not possible to use custom colors for tag references, as they are displayed by the system. There are only two workarounds to change them, or you can set the system colors used to render or parse the link font, and completely make the text TLinkLabel your own, making TLinkLabel useless.

+10
source

Source: https://habr.com/ru/post/917599/


All Articles