Using VCL TNumberBox Control

From RAD Studio
Jump to: navigation, search

Go Up to VCL


The VCL TNumberBox control is a modern looking numeric input control, modeled after the Windows platform WinUI NumberBox control. The control supports the input of integer numbers, floating point numbers with a given set of decimal digits and proper formatting, and currency values.

Object inspector1.png

The user can increase or decrease the value using arrow buttons or allow keys or mouse wheel, and also increase and decrease by a large value using Page Up and Page Down keys.

The component supports simple expression evaluation; if enabled, a user can input an expression like 40 + 2 and the control will replace it with the result.

The control supports computing inline calculations of basic equations such as multiplication, division, addition, and subtraction (allowing the use of parentheses). Notice that you can use the symbols + and - both as binary and unary operations, so you can type -23 or + 23, you can write 55+23 and 55-23, and even combine them as in 53++23 or 53--23, which is evaluated as 53 - (-23). thus, adds the two values.

The component includes an optional spin button, configured with the SpinButtonOptions Placement property, which can be compact, inline, or disabled, as you can see below:

SpinButton2.png

List of TNumberBox Component Properties

The control supports VCL styling, is HighDPI-enabled, and has many additional properties to adjust visual style and behavior. This is a list of the control properties:

  • Mode: TNumberBoxMode

Defines in which mode control works and is based on the following enumeration: TNumberBoxMode = (nbmInteger, nbmFloat, nbmCurrency);

  • Value: Extended

Current Value

  • ValueInt: Integer

Current Value as Integer

  • ValueFloat: Extended

Current Value as Extended rounded using Decimal property

  • ValueCurrency: Extended

Current Value as Extended rounded with Decimal = 2

  • CurrencyString: String

Defines string for currency mode, which will be added at the end of display text

  • DisplayFormat: String

Defines custom text format

  • MinValue: Extended

Defines minimum value

  • MaxValue: Extended

Defines maximum value

  • Decimal: Byte

Defines the number of decimal digits

  • SmallStep: Extended

Defines the amount by which the Value property will change with spin button, Up/Down keys and mouse wheel

  • LargeStep: Extended

Defines the amount by which the Value property will change with Page Up/Page Down keys

  • AcceptExpressions: Boolean

Enables using expressions in control

  • SpinButtonOptions: TNumberBoxSpinButtonOptions

Defines options of spin button and is a data structure including sub-properties ButtonWidth, Placement, RepeatTimerInterval, ShowInlineDividers, and different arrow colors

  • UseNaNValue: Boolean

Uses NaN value with empty text

  • UseMouseWheel: Boolean

Enables changing Value with mouse wheel using SmallStep property

  • UseUpDownKeys: Boolean

Enables changing Value with Up/Downand Page Up/Page Down keys

  • Wrap: Boolean

Enables incrementing from the max value to the minimum one and reverse

List of TNumberBox Component Events

The component has the following events:

  • OnChangeValue: TNotifyEvent

Occurs if Value property is changed

  • OnEvaluateExpression: TNotifyEvent

Occurs when applying custom evaluation of expression using Text and Value properties

  • OnValidateChar: TNumberBoxValidateCharEvent

Custom validation of input char