Вот пример вывода цветного текста. А как его вывести на кнопку- зависит от того, что за компонент ее представляет.
| Код | procedure DrawColoredText(const X, Y: Integer; const AText: string; Canvas: TCanvas; const Colors: array of TColor); var P, N, LettersPerColor, H, L: Integer; S: string; begin LettersPerColor := Length(AText) div Length(Colors); H := High(Colors);
L := X; P := 1; N := Low(Colors); while N <= H do begin S := Copy(AText, P, LettersPerColor);
Canvas.Font.Color := Colors[N]; Canvas.TextOut(L, Y, S);
Inc(P, LettersPerColor); Inc(L, Canvas.TextWidth(S)); Inc(N); end; end;
procedure TForm1.Button1Click(Sender: TObject); begin DrawColoredText(100, 100, 'Colored text', Canvas, [clRed, clBlue, clYellow, clGreen]); end;
| |