Einzelnen Beitrag anzeigen

Aviator

Registriert seit: 3. Jun 2010
1.611 Beiträge
 
Delphi 10.3 Rio
 
#4

AW: VirtualStringTree Text with multiColor

  Alt 30. Okt 2013, 20:22
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.
  Mit Zitat antworten Zitat