我希望将显示的文本或TNumberBox格式化,例如当value = 0时显示“零”,显示千位分隔符等。
有没有办法做到这一点?
答案 0 :(得分:1)
您可以在OnPaint()
事件中执行以下操作:
procedure TForm14.NumberBox1Paint(Sender: TObject; Canvas: TCanvas;
const ARect: TRectF);
var
nb: TNumberBox;
rf: TRectF;
tx: string;
begin
nb := Sender as TNumberBox;
if nb.Value = 0 then
tx := 'zero'
else
tx := format('%.0n',[nb.Value]);
rf := ARect;
Canvas.ClearRect(ARect, TAlphaColors.Lightpink);
rf.inflate(-4, -2);
Canvas.Fill.Color := TAlphaColors.Black;
Canvas.FillText(rf, tx, False, 1, [], TTextAlign.Leading, TTextAlign.Center);
end;