Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   GUI-Design mit VCL / FireMonkey / Common Controls (https://www.delphipraxis.net/18-gui-design-mit-vcl-firemonkey-common-controls/)
-   -   Delphi VirtualStringTree Text with multiColor (https://www.delphipraxis.net/177316-virtualstringtree-text-multicolor.html)

sdean 30. Okt 2013 19:45

VirtualStringTree Text with multiColor
 
Hello , please i need all your help in this :

Suppose i have this Text on VirtualStringTree cell :

'HELLO'

how can i give Each character a different Color like this :

HELLO

many thanks

Aviator 30. Okt 2013 19:56

AW: VirtualStringTree Text with multiColor
 
Maybe you could use the
Delphi-Quellcode:
OnDrawText
Event of the VST. And I think there you could change the
Delphi-Quellcode:
Canvas.Font.Color
of the TargetCanvas for each letter.

sdean 30. Okt 2013 20:01

AW: VirtualStringTree Text with multiColor
 
Zitat:

Zitat von Aviator (Beitrag 1233854)
Maybe you could use the
Delphi-Quellcode:
OnDrawText
Event of the VST. And I think there you could change the
Delphi-Quellcode:
Canvas.Font.Color
of the TargetCanvas for each letter.

many thanks Aviator , i really need a little code ....

Aviator 30. Okt 2013 20:22

AW: VirtualStringTree Text with multiColor
 
Maybe you could do it like this:

Delphi-Quellcode:
procedure TMainFrm.MainVSTDrawText(Sender: TBaseVirtualTree; TargetCanvas: TCanvas; Node: PVirtualNode;
  Column: TColumnIndex; const Text: string; const CellRect: TRect; var DefaultDraw: Boolean);
var
  i, TotalWidth : Integer;
begin
  DefaultDraw := False;
  if Node.Index = 1 then begin
    TotalWidth := 0;
    for i := 0 to Length(Text) - 1 do begin
      if (i mod 2 = 0) then
        TargetCanvas.Font.Color := clBlue
      else
        TargetCanvas.Font.Color := clRed;

      TargetCanvas.TextOut(CellRect.Left + TotalWidth, CellRect.Top, Text[i]);
      Inc(TotalWidth, TargetCanvas.TextWidth(Text[i]));

    end;
  end else
    DefaultDraw := True;
end;
But I really don't know if this is the right and/or fastest way to do this.

Happy testing. :wink:

Aviator 30. Okt 2013 20:23

AW: VirtualStringTree Text with multiColor
 
Liste der Anhänge anzeigen (Anzahl: 1)
Sorry for double posting, but I forgot the sample picture.


Alle Zeitangaben in WEZ +1. Es ist jetzt 15:05 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz