It's possible, but you'll have to take over the Windows Paint
and PaintRegion
methods to do it well (with a genuine gradient).
Also, set DefaultDraw
to false before you return, or all the work you just did will be overwritten...
Question
I am trying to assign multiple colors like a gradient to text in TListView, i tried searching but on the internet all i was able to find was the single color method, i tried with drawing one character at a time and changing colors but that does not work either. Here is the code i tried.
procedure TForm1.lvMainAdvancedCustomDrawItem(Sender: TCustomListView; Item: TListItem; State: TCustomDrawState; Stage: TCustomDrawStage; var DefaultDraw: Boolean);
var txtWidth: Integer;
Rct: TRect;
begin
Rct := item.DisplayRect(drBounds);
lvMain.Canvas.Font.Color := clRed;
DrawText(lvMain.Canvas.Handle, 'asd', 3, Rct, DT_SINGLELINE);
Canvas.Refresh;
lvMain.Canvas.Font.Color := clBlack;
txtWidth := Canvas.TextWidth('asd');
Rct.Left := Rct.Left + txtWidth;
DrawText(lvMain.Canvas.Handle, 'b', 1, Rct, DT_SINGLELINE);
lvMain.Canvas.Font.Color := clBlue;
txtWidth := Canvas.TextWidth('b');
Rct.Left := Rct.Left + txtWidth;
DrawText(lvMain.Canvas.Handle, 'sa', 2, Rct, DT_SINGLELINE);
end;
It still result in a single color. any suggestions on how to achieve this?
Thanks
La solution
It's possible, but you'll have to take over the Windows Paint
and PaintRegion
methods to do it well (with a genuine gradient).
Also, set DefaultDraw
to false before you return, or all the work you just did will be overwritten...