Class DoubleTextBox
Extends the System.Windows.Forms.TextBox class to handle double input and validation.
Inheritance
Implements
Inherited Members
Namespace: Syncfusion.Windows.Forms.Tools
Assembly: Syncfusion.Shared.Base.dll
Syntax
public class DoubleTextBox : NumericTextBox, IThemeProvider, IVisualStyle, ISupportInitialize, ISerializable
Remarks
The DoubleTextBox is derived from textbox and provides all the functionality of a textbox and adds additional functionality of its own.
Collecting double input in a consistent format requires validation code that needs to be built into the application when using the Windows Forms text box control. The DoubleTextBox includes all this logic into its methods and properties and makes it easy for the developer and the end user to collect and enter double data.
The DoubleTextBox is also closely tied to the globalization settings of the operating system for number related properties. Please refer to the System.Globalization.NumberFormatInfo class for a detailed explanation of globalization and number related attributes.
The DoubleTextBox has full support for the Windows Forms designer and you can just drag-and-drop and set properties on the control just as you would with the Windows Forms text box.
The DoubleTextBox also raises a ValidationError event when in appropriate data is entered into the control.
All clipboard functions such as copy, paste and cut are also supported with special accommodations for number related issues.
Constructors
DoubleTextBox()
Overloaded. Creates an object of type DoubleTextBox.
Declaration
public DoubleTextBox()
Remarks
The DoubleTextBox object will be initialized with the default values for the display and data properties. You need to set any specific values.
Properties
AccessibilityEnabled
Gets or sets a value indicating whether the control should enable its Accessibility support.
Declaration
public bool AccessibilityEnabled { get; set; }
Property Value
| Type |
|---|
| System.Boolean |
DoubleValue
Gets or sets the double value of the control. This will be formatted and displayed.
Declaration
public double DoubleValue { get; set; }
Property Value
| Type |
|---|
| System.Double |
HideTrailingZeros
Gets or sets a value indicating whether trailing zeros should be hidden in the displayed number.
Declaration
public bool HideTrailingZeros { get; set; }
Property Value
| Type |
|---|
| System.Boolean |
MaxValue
Gets or sets the maximum value that can be set through the DoubleTextBox.
Declaration
public double MaxValue { get; set; }
Property Value
| Type |
|---|
| System.Double |
MinValue
Gets or sets the minimum value that can be set through the DoubleTextBox.
Declaration
public double MinValue { get; set; }
Property Value
| Type |
|---|
| System.Double |
Text
Overrides the Text property of System.Windows.Forms.TextBox.
Declaration
public override string Text { get; set; }
Property Value
| Type |
|---|
| System.String |
Remarks
This property is overriden in order to normalize the data that is set to the Text property and format it as needed. The method InsertString is used to format the data.
ThemeStyle
Gets or sets the DoubleTextBoxVisualStyle value used to customize the appearance of the DoubleTextBox.
Declaration
public DoubleTextBoxVisualStyle ThemeStyle { get; set; }
Property Value
| Type |
|---|
| DoubleTextBoxVisualStyle |
Remarks
This ThemeStyle settings will be applied only when the VisualStyleBased theme has been applied to the control.
UseNullString
Indicates whether the NULLString property will be used.
Declaration
[Obsolete("This property will not be used in future.Insead Use AllowNull")]
public bool UseNullString { get; set; }
Property Value
| Type |
|---|
| System.Boolean |
Methods
ApplyFormatting(String)
Formats the given text according to the current setting.
Declaration
protected override string ApplyFormatting(string rawValue)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | rawValue |
Returns
| Type |
|---|
| System.String |
Overrides
CheckForMinMax(String, Boolean)
Checks whether the current text value is within the defined minimum and maximum range.
Declaration
protected override bool CheckForMinMax(string currentTextValue, bool ignoreLength)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | currentTextValue | The text value to validate. |
| System.Boolean | ignoreLength | Indicates whether to ignore length constraints. |
Returns
| Type |
|---|
| System.Boolean |
Overrides
CheckIfNegative(String)
Checks whether the specified raw value represents a negative number.
Declaration
protected override bool CheckIfNegative(string rawValue)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | rawValue | The raw string value to check. |
Returns
| Type |
|---|
| System.Boolean |
Overrides
CheckIsZero()
Checks whether the current value is zero and not null.
Declaration
protected override bool CheckIsZero()
Returns
| Type |
|---|
| System.Boolean |
Overrides
CheckNullStringIsInRange(String)
Checks whether the null string value is within the valid range.
Declaration
protected override bool CheckNullStringIsInRange(string nullString)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | nullString | The string to validate. |
Returns
| Type |
|---|
| System.Boolean |
Overrides
CreateAccessibilityInstance()
Creates a custom accessibility instance for the control if accessibility is enabled.
Declaration
protected override AccessibleObject CreateAccessibilityInstance()
Returns
| Type |
|---|
| System.Windows.Forms.AccessibleObject |
Overrides
Dispose(Boolean)
Releases the unmanaged resources used by the DoubleTextBox and optionally releases the managed resources.
Declaration
protected override void Dispose(bool disposing)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Boolean | disposing | true to release both managed and unmanaged resources; false to release only unmanage resources. |
Overrides
FormatChanged(String, NumberFormatInfo)
Declaration
protected override void FormatChanged(string currentText, NumberFormatInfo previousFormat)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | currentText | |
| System.Globalization.NumberFormatInfo | previousFormat |
Overrides
GetControlName(String)
Helps to override the ThemeName property settings
Declaration
public override string GetControlName(string controlName)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | controlName | ThemeName |
Returns
| Type |
|---|
| System.String |
Overrides
GetNumberPartLength(Double)
Gets the length of the number part from the specified double value.
Declaration
protected int GetNumberPartLength(double numberValue)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Double | numberValue | The number value. |
Returns
| Type |
|---|
| System.Int32 |
GetNumberValue(String, Int32)
Extracts and returns the numeric value from the formatted text starting at the specified position.
Declaration
protected override string GetNumberValue(string formattedText, int startPosition)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | formattedText | The formatted text containing the number. |
| System.Int32 | startPosition | The position to start extraction. |
Returns
| Type |
|---|
| System.String |
Overrides
GetValue()
Gets the current value of the control.
Declaration
protected override object GetValue()
Returns
| Type | Description |
|---|---|
| System.Object | The current value as an object. |
Overrides
HandleBackspaceKey()
Handles the Backspace key press event. If the current value is zero and null is allowed, sets the control to its null state.
Declaration
protected override bool HandleBackspaceKey()
Returns
| Type |
|---|
| System.Boolean |
Overrides
HandleDecimalKey()
Handles the Decimal key press event. Moves the cursor to the decimal separator or enables decimal mode if the value is null.
Declaration
protected override bool HandleDecimalKey()
Returns
| Type |
|---|
| System.Boolean |
Overrides
HandleDeleteKey()
Handles the Delete key press event. If the current value is zero and null is allowed, sets the control to its null state.
Declaration
protected override bool HandleDeleteKey()
Returns
| Type |
|---|
| System.Boolean |
Overrides
HandleSubtractKey()
Handles the Subtract key press event.
If DeleteSelectionOnNegative is enabled, clears the selection at the decimal separator.
Declaration
protected override NumberModifyState HandleSubtractKey()
Returns
| Type |
|---|
| NumberModifyState |
Overrides
InitializeNumberTextBox()
Overrides InitializeNumberTextBox().
Declaration
protected override void InitializeNumberTextBox()
Overrides
IsAssignable(Object)
Determines whether the specified value is assignable to a System.Double.
Declaration
protected override bool IsAssignable(object val)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Object | val | The value to check. |
Returns
| Type |
|---|
| System.Boolean |
Overrides
IsValidNumberValue(String)
Determines whether the specified string represents a valid number.
Declaration
protected override bool IsValidNumberValue(string doubleString)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | doubleString | The string to validate. |
Returns
| Type |
|---|
| System.Boolean |
Overrides
OnDoubleValueChanged(EventArgs)
Raises the DoubleValueChanged event.
Declaration
protected virtual void OnDoubleValueChanged(EventArgs e)
Parameters
| Type | Name | Description |
|---|---|---|
| System.EventArgs | e | A System.EventArgs that contains the event data. |
OnEnabledChanged(EventArgs)
Raises the System.Windows.Forms.Control.EnabledChanged event.
Declaration
protected override void OnEnabledChanged(EventArgs e)
Parameters
| Type | Name | Description |
|---|---|---|
| System.EventArgs | e | An System.EventArgs that contains the event data. |
Overrides
OnEnter(EventArgs)
Overrides the System.Windows.Forms.Control.OnEnter(System.EventArgs) method.
Declaration
protected override void OnEnter(EventArgs args)
Parameters
| Type | Name | Description |
|---|---|---|
| System.EventArgs | args | The event data. |
Overrides
Remarks
Saves the current DoubleValue so that it can be compared during validation. The DoubleValueChanged and TextChanged event will only be raised if the value is different during validation.
OnGotFocus(EventArgs)
Helps to override the OnGotFocus events
Declaration
protected override void OnGotFocus(EventArgs e)
Parameters
| Type | Name | Description |
|---|---|---|
| System.EventArgs | e | An System.EventArgs that contains the event data. |
Overrides
OnKeyDown(KeyEventArgs)
Raises the System.Windows.Forms.Control.KeyDown event.
Declaration
protected override void OnKeyDown(KeyEventArgs e)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Windows.Forms.KeyEventArgs | e | A System.Windows.Forms.KeyEventArgs that contains the event data. |
OnLostFocus(EventArgs)
Handles the lost focus event and updates the text box formatting.
Declaration
protected override void OnLostFocus(EventArgs e)
Parameters
| Type | Name | Description |
|---|---|---|
| System.EventArgs | e | An System.EventArgs that contains the event data. |
Overrides
OnTextChanged(EventArgs)
Overrides OnTextChanged.
Declaration
protected override void OnTextChanged(EventArgs e)
Parameters
| Type | Name | Description |
|---|---|---|
| System.EventArgs | e | The event data. |
Overrides
OnThemeNameChanged(String)
Helps to apply the ThemeName settings in control
Declaration
public override void OnThemeNameChanged(string themeName)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | themeName | ThemeName |
Overrides
OnValidated(EventArgs)
Handles the validated event and triggers control-specific validation logic.
Declaration
protected override void OnValidated(EventArgs e)
Parameters
| Type | Name | Description |
|---|---|---|
| System.EventArgs | e | An System.EventArgs that contains the event data. |
OnValidating(CancelEventArgs)
Handles the validating event to ensure the value is within the allowed range. Applies corrective actions based on the OnValidationFailed setting.
Declaration
protected override void OnValidating(CancelEventArgs e)
Parameters
| Type | Name | Description |
|---|---|---|
| System.ComponentModel.CancelEventArgs | e | A System.ComponentModel.CancelEventArgs that contains the event data. |
Overrides
PrepareInsertString(String, Int32, Int32, String, Boolean)
Prepares the control for inserting a string, handling formatting and validation.
Declaration
protected override NumberModifyState PrepareInsertString(string currentText, int startPosition, int selectionLength, string textToBeInserted, bool pasteOperation)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | currentText | The current text in the control. |
| System.Int32 | startPosition | The position at which the new text will be inserted. |
| System.Int32 | selectionLength | The length of the selected text to be replaced. |
| System.String | textToBeInserted | The text to be inserted. |
| System.Boolean | pasteOperation | Indicates whether the operation is a paste action. |
Returns
| Type |
|---|
| NumberModifyState |
Overrides
ResetText()
Restores the CurrencyNumberDigits to the MaximumLength.
Declaration
protected void ResetText()
SetDoubleValue(Double)
Sets the double value of the control, applying rounding and formatting.
Declaration
protected void SetDoubleValue(double newValue)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Double | newValue | The new double value to set. |
SetNullNumberValue()
Sets the control's value to represent a null number.
Declaration
protected override void SetNullNumberValue()
Overrides
SetTextProperty(String)
Sets the text property of the control, parsing and validating the input.
Declaration
protected override void SetTextProperty(string newText)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | newText | The new text to assign. |
Overrides
SetValue(Object)
Sets the control's value using the specified object.
Declaration
protected override void SetValue(object val)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Object | val | The value to assign. |
Overrides
ShouldSerializeText()
Indicates whether to serialize the Text property if it is null or quals NullString
Declaration
protected bool ShouldSerializeText()
Returns
| Type |
|---|
| System.Boolean |
ToggleNegative(String)
Toggles the sign of the numeric value represented by the input text. If the result is zero, updates the zero-negative state.
Declaration
protected override string ToggleNegative(string currentText)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | currentText | The current numeric text. |
Returns
| Type |
|---|
| System.String |
Overrides
Events
DoubleValueChanged
Occurs when the DoubleValue property is changed.
Declaration
public event EventHandler DoubleValueChanged
Event Type
| Type |
|---|
| System.EventHandler |