I want the displayed text o a TNumberBox to be formatted eg. when value = 0 to show 'zero', showing thousands separator etc.
Is there a way to do this ?
I want the displayed text o a TNumberBox to be formatted eg. when value = 0 to show 'zero', showing thousands separator etc.
Is there a way to do this ?
You can do it in the OnPaint()
event as follows:
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;
TNumberBox
is a primitive control with few options. It's a minor addition to aTCustomEditBox
- have a look at how the FMX framework implements it. I'd suggest rolling your own in the same way, implementing your custom formatting in theConvertTextToValue
andConvertToText
methods of a new descendentTEditBoxModel
.