有没有办法格式化TNumberBox.text?

问题描述 投票:0回答:1

我希望TNumberBox的显示文本格式化,例如。当value = 0时显示'零',显示千位分隔符等

有没有办法做到这一点 ?

delphi format firemonkey
1个回答
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;
© www.soinside.com 2019 - 2024. All rights reserved.