Class NumberTextBoxBase
Extends the System.Windows.Forms.TextBox class to handle numeric input and validation.
Inheritance
Implements
Inherited Members
Namespace: Syncfusion.Windows.Forms.Tools
Assembly: Syncfusion.Shared.Base.dll
Syntax
public class NumberTextBoxBase : TextBoxExt, IThemeProvider, ISupportInitialize, ISerializable, IVisualStyle
Remarks
The NumberTextBoxBase class is not to be used directly. Defines the base class for controls that provide specific formatting and validation for different data types.
Constructors
NumberTextBoxBase()
Overloaded. Creates an object of type NumberTextBox.
Declaration
public NumberTextBoxBase()
Remarks
The NumberTextBox object will be initialized with the default values for the display and data properties. You need to set any specific values.
Fields
ignoreTextChange
Internal variable to suppress TextChanged event.
Declaration
protected bool ignoreTextChange
Field Value
Type |
---|
System.Boolean |
initNumberFormatInfoObject
Support for NumberFormatInfo initialization.
Declaration
protected NumberFormatInfo initNumberFormatInfoObject
Field Value
Type |
---|
System.Globalization.NumberFormatInfo |
m_bDecimalMode
Decimal typing mode. Use if NullString is true;
Declaration
protected bool m_bDecimalMode
Field Value
Type |
---|
System.Boolean |
rollBackOperation
Indicates whether an operation is to be rolled back because of an error.
Declaration
protected bool rollBackOperation
Field Value
Type |
---|
System.Boolean |
supressKeyPress
Indicates whether to allow the KeyPress event to be raised but no other action to be taken by the base class.
Declaration
protected bool supressKeyPress
Field Value
Type |
---|
System.Boolean |
Properties
AllowNull
Gets or sets the NULL string to be displayed.
Declaration
public virtual bool AllowNull { get; set; }
Property Value
Type |
---|
System.Boolean |
BackColor
Gets or sets the back color. (overridden property)
Declaration
public Color BackColor { get; set; }
Property Value
Type |
---|
System.Drawing.Color |
BackGroundColor
Gets or Sets the BackGroundColor of the control.
Declaration
public Color BackGroundColor { get; set; }
Property Value
Type |
---|
System.Drawing.Color |
BindableValue
Wrapper property around the selected value. Use this property if you want to be able to set the value of the control to NULL.
Declaration
public object BindableValue { get; set; }
Property Value
Type |
---|
System.Object |
CanUndo
Indicates whether the Undo operation is possible at this time.
Declaration
public bool CanUndo { get; }
Property Value
Type |
---|
System.Boolean |
Remarks
The NumberTextBox maintains its own undo mechanism and hence needs to implement this method to be compatible with the Undo mechanism.
ClipMode
Determines whether to include or exclude the literal characters in the input mask when doing a copy command.
Declaration
public CurrencyClipModes ClipMode { get; set; }
Property Value
Type |
---|
CurrencyClipModes |
Remarks
This property is used when copying to the clipboard and also the Syncfusion.Text property.
When databinding the Text property, it is advisable to have the ClipMode set to ExcludeFormatting in cases where the data source does not accept the formatted text.
ClipText
Returns the clipped text without the formatting.
Declaration
public virtual string ClipText { get; set; }
Property Value
Type |
---|
System.String |
Remarks
For example, if the text in the CurrencyTextBox is $45,000.00, the ClipText property will give 45000.00.
Culture
Gets or sets the culture that is to be used for formatting the numeric display.
Declaration
public CultureInfo Culture { get; set; }
Property Value
Type |
---|
System.Globalization.CultureInfo |
CurrentCultureRefresh
Indicates whether the Culture property is to be refreshed when the culture changes.
Declaration
public bool CurrentCultureRefresh { get; set; }
Property Value
Type |
---|
System.Boolean |
DefaultValue
Gets or set the default value.
Declaration
public object DefaultValue { get; set; }
Property Value
Type |
---|
System.Object |
EnforceMinMaxDuringValidating
If the Min Max values are not met, the Validating event will be handled and cancelled if this property is set to true.
Declaration
[Obsolete("This property will be removed, use OnValidationFailed.KeepFocus Property instead.")]
public bool EnforceMinMaxDuringValidating { get; set; }
Property Value
Type |
---|
System.Boolean |
ForeColor
Please use NegativeColor, ZeroColor and PositiveColor properties instead of ForeColor property.
Declaration
public Color ForeColor { get; set; }
Property Value
Type |
---|
System.Drawing.Color |
FormattedText
Returns the formatted text with the formatting.
Declaration
public virtual string FormattedText { get; set; }
Property Value
Type |
---|
System.String |
Remarks
For example, if the Text in the CurrencyTextBox is $45,000.00, the FormattedText property will give $45,000.00.
IsNegative
Declaration
protected bool IsNegative { get; set; }
Property Value
Type |
---|
System.Boolean |
IsNull
Indicates whether the field is Null(NullString) or Not.
Declaration
public bool IsNull { get; }
Property Value
Type |
---|
System.Boolean |
Remarks
when this is True and AllowNull is True the field will be assigned with NullString
MaxLength
Overrides the MaxLength property. This has no effect on this EditControl as it does not honor MinValue and MaxValue properties.
Declaration
public int MaxLength { get; set; }
Property Value
Type |
---|
System.Int32 |
Remarks
The PercentTextBox control does not honor the
MaxLength property. Set the
MinMaxValidation
Specifies when the MinMax Validation Need to be performed.
Declaration
public MinMaxValidation MinMaxValidation { get; set; }
Property Value
Type |
---|
MinMaxValidation |
NegativeColor
Gets or sets the forecolor when the current value is negative.
Declaration
public Color NegativeColor { get; set; }
Property Value
Type |
---|
System.Drawing.Color |
Remarks
You can customize the look and provide feedback to the user by defining a different color for the negative numbers.
NegativeInputPendingOnSelectAll
This property defines the behavior when the contents of the TextBox is fully selected and the negative key is pressed by the user. If the value is set to True - The current value is not changed at all. The next key stroke is taken to be a new value and the entire contents of the TextBox is replaced by the negative value of the key stroke character entered. Example: If the current value of the TextBox is 1.00 and all the text is selected and the user presses the -ve key followed by the key 5 - the value is -5.00 If the value is set to False - The current value is changed to the negative value immediately. Example: If the current value of the TextBox is 1.00 and all the text is selected and the user presses the -ve key the value is -1.00
Declaration
public bool NegativeInputPendingOnSelectAll { get; set; }
Property Value
Type |
---|
System.Boolean |
NegativeSign
Gets or sets the sign that is to be used to indicate a negative value.
Declaration
public string NegativeSign { get; set; }
Property Value
Type |
---|
System.String |
Remarks
This value is initially set from the System.Globalization.NumberFormatInfo and can be changed based on your requirements or based on the locale.
NullFormat
Returns the NumberFormatInfo object for the NULL display.
Declaration
public NumberFormatInfo NullFormat { get; }
Property Value
Type |
---|
System.Globalization.NumberFormatInfo |
NullState
Indicates the NULLState of the control.
Declaration
[Obsolete("This property will not be used in the future versions. Use IsNull instead to check if the value is null.")]
public bool NullState { get; set; }
Property Value
Type |
---|
System.Boolean |
NullString
Gets or sets the NULL string to be displayed.
Declaration
public string NullString { get; set; }
Property Value
Type |
---|
System.String |
NumberFormatInfoObject
Gets or sets the NumberFormatInfo object that will be used for formatting the number value.
Declaration
public NumberFormatInfo NumberFormatInfoObject { get; set; }
Property Value
Type |
---|
System.Globalization.NumberFormatInfo |
Remarks
This property will not be exposed to the developer. This is only meant to be an accessor for use within the control. The developer will be able to access the properties of the NumberFormatInfo through the individual properties exposed.
OnValidationFailed
Specifies the action to be performed when validation fails, Effective only if MinMaxValidation is set to OnLostFocus
Declaration
public OnValidationFailed OnValidationFailed { get; set; }
Property Value
Type |
---|
OnValidationFailed |
OverWriteText
Gets or sets a value indicating whether to overrite the immediate text when the text cannot be inserted. Effective when MinMaxValidation is set to OnKeyPress.
Declaration
public bool OverWriteText { get; set; }
Property Value
Type |
---|
System.Boolean |
PositiveColor
Gets or sets the forecolor when the current value is positive.
Declaration
public Color PositiveColor { get; set; }
Property Value
Type |
---|
System.Drawing.Color |
Remarks
You can customize the look and provide feedback to the user by defining a different color for the positive numbers.
ReadOnlyBackColor
Color to be used for the Backcolor when the control is Read-only.
Declaration
public Color ReadOnlyBackColor { get; set; }
Property Value
Type |
---|
System.Drawing.Color |
ReturnBaseText
Declaration
protected bool ReturnBaseText { get; set; }
Property Value
Type |
---|
System.Boolean |
RightToLeft
Gets or sets a value indicating whether control's elements are aligned to support locales using right-to-left fonts.
Declaration
public RightToLeft RightToLeft { get; set; }
Property Value
Type |
---|
System.Windows.Forms.RightToLeft |
SelectAllOnFocus
Specifies if the text should be selected when the control gets the focus.
Declaration
public bool SelectAllOnFocus { get; set; }
Property Value
Type |
---|
System.Boolean |
SelectedText
Gets or sets SelectedText. (overridden property)
Declaration
public override string SelectedText { get; set; }
Property Value
Type |
---|
System.String |
SpecialCultureValue
Gets or sets the mode for the cultures.
Declaration
public SpecialCultureValues SpecialCultureValue { get; set; }
Property Value
Type |
---|
SpecialCultureValues |
UseNullString
Indicates whether the NULLString property will be used.
Declaration
[Obsolete("This property will not be used in future.Use AllowNull instead")]
public bool UseNullString { get; set; }
Property Value
Type |
---|
System.Boolean |
UseUserOverride
The UseUserOverride parameter for CultureInfo.
Declaration
public bool UseUserOverride { get; set; }
Property Value
Type |
---|
System.Boolean |
Remarks
The NumberTextBoxBase control has several properties that expose culture-specific information. These properties use a System.Globalization.NumberFormatInfo object for handling the culture specific information. This property is used in the creation of the NumberFormatInfo object. System.Globalization.CultureInfo.UseUserOverride
ZeroColor
Gets or sets the forecolor when the current value is zero.
Declaration
public Color ZeroColor { get; set; }
Property Value
Type |
---|
System.Drawing.Color |
Remarks
You can customize the look and provide feedback to the user by defining a different color for displaying zero.
Methods
ApplyFormatting(String)
Formats the given text according to the current setting.
Declaration
protected virtual string ApplyFormatting(string rawValue)
Parameters
Type | Name | Description |
---|---|---|
System.String | rawValue |
Returns
Type |
---|
System.String |
ApplyFormattingAndSetText(String)
Takes the incoming text, formats it based on the rules and settings prevailing currently and sets the display accordingly. Returns the length of the new text after setting the display.
Declaration
protected string ApplyFormattingAndSetText(string rawValue)
Parameters
Type | Name | Description |
---|---|---|
System.String | rawValue |
Returns
Type |
---|
System.String |
ApplyRightToLeft()
Declaration
protected void ApplyRightToLeft()
CanInsert(String, String, Int32)
Checks if the text can be inserted subject to the constraints.
Declaration
protected virtual int CanInsert(string currentText, string inputText, int initialZeroCount)
Parameters
Type | Name | Description |
---|---|---|
System.String | currentText | The current content of the text box. |
System.String | inputText | The text to be inserted. |
System.Int32 | initialZeroCount |
Returns
Type | Description |
---|---|
System.Int32 | The length of the acceptable string to be inserted. |
CheckDecimalPartLength(String)
Checks the length of the decimal part of the text box content.
Declaration
protected string CheckDecimalPartLength(string rawText)
Parameters
Type | Name | Description |
---|---|---|
System.String | rawText | The input raw text string. |
Returns
Type | Description |
---|---|
System.String | The checked string. |
CheckForMinMax(String)
Declaration
protected virtual bool CheckForMinMax(string newText)
Parameters
Type | Name | Description |
---|---|---|
System.String | newText |
Returns
Type |
---|
System.Boolean |
CheckForMinMax(String, Boolean)
Indicates whether the given value meets the minimum and maximum value considerations.
Declaration
protected virtual bool CheckForMinMax(string newText, bool ignoreLength)
Parameters
Type | Name | Description |
---|---|---|
System.String | newText | |
System.Boolean | ignoreLength |
Returns
Type |
---|
System.Boolean |
CheckIfNegative(String)
Declaration
protected virtual bool CheckIfNegative(string rawValue)
Parameters
Type | Name | Description |
---|---|---|
System.String | rawValue |
Returns
Type |
---|
System.Boolean |
CheckIsZero()
Declaration
protected virtual bool CheckIsZero()
Returns
Type |
---|
System.Boolean |
CheckNullStringIsInRange(String)
Checks whether the NullSring Value is with in the Min Max Values
Declaration
protected virtual bool CheckNullStringIsInRange(string nullString)
Parameters
Type | Name | Description |
---|---|---|
System.String | nullString |
Returns
Type | Description |
---|---|
System.Boolean | True if it is in range else false |
Examples
Double doubleVal;
bool isNumber = Double.TryParse(currentTextValue, out doubleVal);
if (isNumber)
{
return CheckForMinMax(doubleVal.ToString(),true);
}
else
return true;
CompleteInsertString(NumberModifyState)
Declaration
protected virtual bool CompleteInsertString(NumberModifyState state)
Parameters
Type | Name | Description |
---|---|---|
NumberModifyState | state |
Returns
Type |
---|
System.Boolean |
CompleteSubtractKey(NumberModifyState)
Declaration
protected virtual bool CompleteSubtractKey(NumberModifyState state)
Parameters
Type | Name | Description |
---|---|---|
NumberModifyState | state |
Returns
Type |
---|
System.Boolean |
ConcatModifiedText(String, String, String)
Concat modified text.
Declaration
protected virtual string ConcatModifiedText(string startCurrentText, string inputRawText, string endCurrentText)
Parameters
Type | Name | Description |
---|---|---|
System.String | startCurrentText | |
System.String | inputRawText | |
System.String | endCurrentText |
Returns
Type |
---|
System.String |
Copy()
Copies the content of the NumberTextBox to the clipboard. The ClipMode property dictates what gets copied.
Declaration
public virtual void Copy()
Remarks
If the text of the control is $56,000.12, this is the content that will be copied to the clipboard based on whether the ClipMode is set to IncludeFormatting or ExcludeFormatting.
IncludeFormatting - $56,000.12 ExcludeFormatting - 56000.12
CursorShouldBeMoved(Int32, Boolean)
When the start position is in the number part and there is only a zero, the cursor should be moved.
Declaration
protected virtual int CursorShouldBeMoved(int startPosition, bool inDecimalPosition)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | startPosition | |
System.Boolean | inDecimalPosition |
Returns
Type |
---|
System.Int32 |
Cut()
Cuts the selected data to the clipboard.
Declaration
public virtual void Cut()
Remarks
The selected text in the CurrencyTextBox will be deleted and the content will be copied to the clipboard.
Delete()
Deletes the current selection of the text box.
Declaration
public virtual void Delete()
Remarks
This method is invoked by the ContextMenu "Delete" menu item of the text box through the "Del" shortcut or by selecting the menu item. If you want to override the default behavior of this method, derive and override this method to provide your own implementation.
DeleteSelectedText()
Deletes the currently selected text.
Declaration
protected string DeleteSelectedText()
Returns
Type | Description |
---|---|
System.String | The content of the text box after deletion. |
DeleteSelectedText(String, Int32, Int32)
Deletes the currently selected text.
Declaration
protected string DeleteSelectedText(string formattedText, int startPosition, int endPosition)
Parameters
Type | Name | Description |
---|---|---|
System.String | formattedText | |
System.Int32 | startPosition | |
System.Int32 | endPosition |
Returns
Type | Description |
---|---|
System.String | The content of the text box after deletion. |
Dispose(Boolean)
Declaration
protected override void Dispose(bool disposing)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | disposing |
Overrides
EndInit()
Implementation of the System.ComponentModel.ISupportInitialize interface.
Declaration
public override void EndInit()
Overrides
FormatChanged(String, NumberFormatInfo)
Declaration
protected virtual void FormatChanged(string currentText, NumberFormatInfo previousFormat)
Parameters
Type | Name | Description |
---|---|---|
System.String | currentText | |
System.Globalization.NumberFormatInfo | previousFormat |
GetClipText()
Declaration
protected virtual string GetClipText()
Returns
Type |
---|
System.String |
GetClipText(Boolean)
Gets the clip text.
Declaration
public string GetClipText(bool padIfEmpty)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | padIfEmpty |
Returns
Type |
---|
System.String |
GetCopyOfCurrentNumberFormatInfo()
Returns a copy of the current NumberFormatInfo.
Declaration
protected NumberFormatInfo GetCopyOfCurrentNumberFormatInfo()
Returns
Type |
---|
System.Globalization.NumberFormatInfo |
GetDecimalDigits()
Declaration
protected virtual int GetDecimalDigits()
Returns
Type |
---|
System.Int32 |
GetDecimalSeparator()
Overloaded. Override this to return DecimalSeparator in NumberTextBox.
Declaration
protected virtual string GetDecimalSeparator()
Returns
Type |
---|
System.String |
GetDecimalSeparator(NumberFormatInfo)
Override this to return DecimalSeparator in NumberTextBox.
Declaration
protected virtual string GetDecimalSeparator(NumberFormatInfo info)
Parameters
Type | Name | Description |
---|---|---|
System.Globalization.NumberFormatInfo | info |
Returns
Type |
---|
System.String |
GetDecimalSeparatorPosition(String)
Overloaded. Returns the position of the decimal separator taking into account the CurrencySymbol.
Declaration
protected virtual int GetDecimalSeparatorPosition(string currentText)
Parameters
Type | Name | Description |
---|---|---|
System.String | currentText | The text in which to look for the decimal separator. |
Returns
Type | Description |
---|---|
System.Int32 | The decimal separator's position. |
GetDecimalSeparatorPosition(String, NumberFormatInfo)
Returns the position of the decimal separator taking into account the CurrencySymbol.
Declaration
protected virtual int GetDecimalSeparatorPosition(string currentText, NumberFormatInfo info)
Parameters
Type | Name | Description |
---|---|---|
System.String | currentText | The text in which to look for the decimal separator. |
System.Globalization.NumberFormatInfo | info |
Returns
Type | Description |
---|---|
System.Int32 | The decimal separator's position. |
GetFirstDataPos()
Returns the first data position which is the index within the current string content of the edit control at which data can be inserted.
Declaration
protected int GetFirstDataPos()
Returns
Type | Description |
---|---|
System.Int32 | The index of the first possible data position. |
GetGroupSeparator()
Overloaded. Override this to return GroupSeparator in NumberTextBox.
Declaration
protected virtual string GetGroupSeparator()
Returns
Type |
---|
System.String |
GetGroupSeparator(NumberFormatInfo)
Override this to return GroupSeparator in NumberTextBox.
Declaration
protected virtual string GetGroupSeparator(NumberFormatInfo info)
Parameters
Type | Name | Description |
---|---|---|
System.Globalization.NumberFormatInfo | info |
Returns
Type |
---|
System.String |
GetInitialZeroCount(String, Int32)
Returns the count of zeros at the beginning of the string. This is needed as we will have to compensate for this once a valid number appears after it for repositioning the cursor.
Declaration
protected virtual int GetInitialZeroCount(string currentText, int startPosition)
Parameters
Type | Name | Description |
---|---|---|
System.String | currentText | |
System.Int32 | startPosition |
Returns
Type |
---|
System.Int32 |
GetNegativeInputPending()
Declaration
protected bool GetNegativeInputPending()
Returns
Type |
---|
System.Boolean |
GetNextDataPos(Int32, Boolean, Boolean, Boolean)
Returns the next valid position for receiving data input.
Declaration
protected int GetNextDataPos(int startPosition, bool inDecimalPosition, bool back, bool delete)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | startPosition | The position to start seeking from. |
System.Boolean | inDecimalPosition | Indicates whether the start position is after the decimal separator. |
System.Boolean | back | Indicates whether the backspace key has been pressed. |
System.Boolean | delete |
Returns
Type | Description |
---|---|
System.Int32 | The index in the string that is valid for input. |
GetNumberPartLength(String)
Declaration
protected int GetNumberPartLength(string numberText)
Parameters
Type | Name | Description |
---|---|---|
System.String | numberText |
Returns
Type |
---|
System.Int32 |
GetNumberValue(String, Int32)
Declaration
protected virtual string GetNumberValue(string formattedText, int startPosition)
Parameters
Type | Name | Description |
---|---|---|
System.String | formattedText | |
System.Int32 | startPosition |
Returns
Type |
---|
System.String |
GetPreserveData()
Declaration
protected bool GetPreserveData()
Returns
Type |
---|
System.Boolean |
GetPrevDataPos(Int32)
Returns the previous valid data position for text input.
Declaration
public int GetPrevDataPos(int startPosition)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | startPosition | The position to seek from. |
Returns
Type |
---|
System.Int32 |
GetStartPositionJustNumbers(String, Int32)
Declaration
protected virtual int GetStartPositionJustNumbers(string currentText, int startPosition)
Parameters
Type | Name | Description |
---|---|---|
System.String | currentText | |
System.Int32 | startPosition |
Returns
Type |
---|
System.Int32 |
GetTextBoxText()
Declaration
protected string GetTextBoxText()
Returns
Type |
---|
System.String |
GetTextBoxTextLength()
Declaration
protected int GetTextBoxTextLength()
Returns
Type |
---|
System.Int32 |
GetValue()
Declaration
protected virtual object GetValue()
Returns
Type |
---|
System.Object |
GetZeroNegative()
Declaration
protected bool GetZeroNegative()
Returns
Type |
---|
System.Boolean |
HandleBackspaceKey()
Handles the backspace key.
Declaration
protected virtual bool HandleBackspaceKey()
Returns
Type | Description |
---|---|
System.Boolean | True if the key was accepted and the action performed; false otherwise. |
Remarks
The backspace key results in one character being removed in front of the current selection if the selection is empty or deletion of the selection if the selection is not empty.
HandleBackspaceKeyChar()
Declaration
protected virtual bool HandleBackspaceKeyChar()
Returns
Type |
---|
System.Boolean |
HandleCharacterKey(Char)
Invoked when a character key is pressed.
Declaration
protected virtual bool HandleCharacterKey(char charToBeInserted)
Parameters
Type | Name | Description |
---|---|---|
System.Char | charToBeInserted | The character to be inserted. |
Returns
Type | Description |
---|---|
System.Boolean | True if the insert was successful; false otherwise. |
Remarks
Character entry is accepted if the character is a valid digit. This method invokes the InsertString method to insert the character into the CurrencyTextBox.
HandleDecimalKey()
Invoked when the decimal key is pressed.
Declaration
protected virtual bool HandleDecimalKey()
Returns
Type | Description |
---|---|
System.Boolean | True if the key is handled; false otherwise. |
Remarks
The defined behavior for this key is to jump to the position immediately after the decimal position.
HandleDeleteKey()
Invoked when the Delete key is pressed.
Declaration
protected virtual bool HandleDeleteKey()
Returns
Type | Description |
---|---|
System.Boolean | True if the key is handle; false otherwise. |
Remarks
This method performs the action of removing the selected text when the delete key was pressed and also positioning the cursor appropriately.
HandleSubtractKey()
Invoked when the negative key is pressed.
Declaration
protected virtual NumberModifyState HandleSubtractKey()
Returns
Type | Description |
---|---|
NumberModifyState | True if the key is handled; false otherwise. |
Remarks
The defined behavior for this key is to toggle the sign (negativity) of the content of the NumberTextBox.
InitializeNumberTextBox()
Declaration
protected virtual void InitializeNumberTextBox()
InsertString(String, Int32, Int32, String)
Declaration
protected virtual bool InsertString(string currentText, int startPosition, int selectionLength, string textToBeInserted)
Parameters
Type | Name | Description |
---|---|---|
System.String | currentText | |
System.Int32 | startPosition | |
System.Int32 | selectionLength | |
System.String | textToBeInserted |
Returns
Type |
---|
System.Boolean |
InsertString(String, Int32, Int32, String, Boolean)
Inserts a string into the textbox at the current position. The string data will be parsed for valid numeric data and only the valid characters will be accepted.
Declaration
protected virtual bool InsertString(string currentText, int startPosition, int selectionLength, string textToBeInserted, bool pasteOperation)
Parameters
Type | Name | Description |
---|---|---|
System.String | currentText | |
System.Int32 | startPosition | |
System.Int32 | selectionLength | |
System.String | textToBeInserted | The string to be inserted. |
System.Boolean | pasteOperation | Paste and Text properties will be treated differently for validation. |
Returns
Type | Description |
---|---|
System.Boolean | True if the operation succeeds. |
Remarks
This method attempts to insert the text passed in as the parameter into the NumberTextBox subject to the constraints imposed by the other attributes of the NumberTextBox such as the maximum length of a the string etc.
IsAssignable(Object)
Declaration
protected virtual bool IsAssignable(object val)
Parameters
Type | Name | Description |
---|---|---|
System.Object | val |
Returns
Type |
---|
System.Boolean |
IsDataPosition(String, Int32)
Declaration
protected virtual bool IsDataPosition(string formattedText, int position)
Parameters
Type | Name | Description |
---|---|---|
System.String | formattedText | |
System.Int32 | position |
Returns
Type |
---|
System.Boolean |
IsInDecimalPosition(String, Int32)
Indicates whether the start position is after the decimal separator.
Declaration
protected virtual bool IsInDecimalPosition(string currentText, int startPosition)
Parameters
Type | Name | Description |
---|---|---|
System.String | currentText | The current text. |
System.Int32 | startPosition | The start position to seek for. |
Returns
Type |
---|
System.Boolean |
IsValidCharacter(Char)
The NumberTextBox accepts numeric digits only. This method checks for numeric input.
Declaration
protected bool IsValidCharacter(char inputCharacter)
Parameters
Type | Name | Description |
---|---|---|
System.Char | inputCharacter | The character to be checked. |
Returns
Type | Description |
---|---|
System.Boolean | True if the character is valid; false otherwise. |
IsValidNumberValue(String)
Declaration
protected virtual bool IsValidNumberValue(string doubleString)
Parameters
Type | Name | Description |
---|---|---|
System.String | doubleString |
Returns
Type |
---|
System.Boolean |
OnBackColorChanged(EventArgs)
Declaration
protected override void OnBackColorChanged(EventArgs e)
Parameters
Type | Name | Description |
---|---|---|
System.EventArgs | e |
OnBindableValueChanged(EventArgs)
Raises the BindableValueChanged event.
Declaration
protected virtual void OnBindableValueChanged(EventArgs e)
Parameters
Type | Name | Description |
---|---|---|
System.EventArgs | e | A System.EventArgs that contains the event data. |
OnClipTextChanged(EventArgs)
Raises the ClipTextChanged event.
Declaration
protected virtual void OnClipTextChanged(EventArgs e)
Parameters
Type | Name | Description |
---|---|---|
System.EventArgs | e | A System.EventArgs that contains the event data. |
OnControlValidated(String, String)
Declaration
protected virtual void OnControlValidated(string newValue, string oldValue)
Parameters
Type | Name | Description |
---|---|---|
System.String | newValue | |
System.String | oldValue |
OnEnter(EventArgs)
Declaration
protected override void OnEnter(EventArgs args)
Parameters
Type | Name | Description |
---|---|---|
System.EventArgs | args |
OnFormattedTextChanged(EventArgs)
Raises the FormattedTextChanged event.
Declaration
protected virtual void OnFormattedTextChanged(EventArgs e)
Parameters
Type | Name | Description |
---|---|---|
System.EventArgs | e | A System.EventArgs that contains the event data. |
OnKeyValidate(KeyValidateEventArgs)
Declaration
protected virtual void OnKeyValidate(KeyValidateEventArgs e)
Parameters
Type | Name | Description |
---|---|---|
KeyValidateEventArgs | e |
OnMouseDown(MouseEventArgs)
Declaration
protected override void OnMouseDown(MouseEventArgs e)
Parameters
Type | Name | Description |
---|---|---|
System.Windows.Forms.MouseEventArgs | e |
Overrides
OnReadOnlyChanged(EventArgs)
Declaration
protected override void OnReadOnlyChanged(EventArgs e)
Parameters
Type | Name | Description |
---|---|---|
System.EventArgs | e |
OnSetNull(SetNullEventArgs)
Declaration
protected virtual void OnSetNull(SetNullEventArgs e)
Parameters
Type | Name | Description |
---|---|---|
SetNullEventArgs | e |
OnTextChanged(EventArgs)
Overrides OnTextChanged.
Declaration
protected override void OnTextChanged(EventArgs e)
Parameters
Type | Name | Description |
---|---|---|
System.EventArgs | e | The event data. |
Overrides
OnValidating(CancelEventArgs)
Overrides System.Windows.Forms.Control.OnValidating(System.ComponentModel.CancelEventArgs) method.
Declaration
protected override void OnValidating(CancelEventArgs args)
Parameters
Type | Name | Description |
---|---|---|
System.ComponentModel.CancelEventArgs | args | The event data. |
Remarks
Raises the ValidationError event when there is unacceptable text in the control.
OnValidationError(ValidationErrorArgs)
Invokes the ValidationError event.
A ValidationErrorEventArgs that contains the event data.Declaration
protected virtual void OnValidationError(ValidationErrorArgs args)
Parameters
Type | Name | Description |
---|---|---|
ValidationErrorArgs | args |
Remarks
The OnValidationError method also allows derived classes to handle the event without attaching a delegate. This is the preferred technique for handling the event in a derived class.
note
Inheritors: When overriding OnValidationError in a derived class, be sure to call the base class's OnValidationError method so that registered delegates receive the event.
ParseForNegativeFormat(String)
Overloaded. Override this method to provide an implementation for parsing a negative value.
Declaration
protected virtual bool ParseForNegativeFormat(string currentText)
Parameters
Type | Name | Description |
---|---|---|
System.String | currentText | The text to be parsed. |
Returns
Type | Description |
---|---|
System.Boolean | True if the value is negative; false otherwise. |
ParseForNegativeFormat(String, NumberFormatInfo)
Override this method to provide an implementation for parsing a negative value.
Declaration
protected virtual bool ParseForNegativeFormat(string currentText, NumberFormatInfo info)
Parameters
Type | Name | Description |
---|---|---|
System.String | currentText | The text to be parsed. |
System.Globalization.NumberFormatInfo | info |
Returns
Type | Description |
---|---|
System.Boolean | True if the value is negative; false otherwise. |
Paste()
Pastes the data in the clipboard into the NumberTextBox control.
Declaration
public virtual void Paste()
Remarks
The data will be formatted before being pasted into the text box.
PositionCursorAfterEdit(Int32, Boolean, Boolean, Boolean)
Invoked for positioning the cursor at the right position after something has changed.
Declaration
protected virtual void PositionCursorAfterEdit(int startPositionJustNumbers, bool inDecimalPosition, bool back, bool delete)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | startPositionJustNumbers | The number of valid numbers before the point. |
System.Boolean | inDecimalPosition | Indicates whether the point comes after the decimal separator. |
System.Boolean | back | Indicates whether the direction is backwards. |
System.Boolean | delete |
PrepareInsertString(String, Int32, Int32, String, Boolean)
Declaration
protected virtual NumberModifyState PrepareInsertString(string currentText, int startPosition, int selectionLength, string textToBeInserted, bool pasteOperation)
Parameters
Type | Name | Description |
---|---|---|
System.String | currentText | |
System.Int32 | startPosition | |
System.Int32 | selectionLength | |
System.String | textToBeInserted | |
System.Boolean | pasteOperation |
Returns
Type |
---|
NumberModifyState |
ProcessKeyEventArgs(ref Message)
Overrides to suppress KeyPress. Only the KeyPress event is raised - no other processing is done.
Declaration
protected override bool ProcessKeyEventArgs(ref Message m)
Parameters
Type | Name | Description |
---|---|---|
System.Windows.Forms.Message | m | The message. |
Returns
Type | Description |
---|---|
System.Boolean | True if the message is a KeyPress; otherwise the base class handles this. |
ProcessKeyMessage(ref Message)
This method overrides the System.Windows.Forms.Control.ProcessKeyMessage(System.Windows.Forms.Message@) method and handles the key messages that are of interest to the NumberTextBox.
Declaration
protected override bool ProcessKeyMessage(ref Message m)
Parameters
Type | Name | Description |
---|---|---|
System.Windows.Forms.Message | m | The message that is to handled. |
Returns
Type | Description |
---|---|
System.Boolean | True if the key message is handled; false otherwise. |
RaiseKeyValidate(Char, String, String)
Declaration
protected virtual bool RaiseKeyValidate(char key, string changedString, string changedValueString)
Parameters
Type | Name | Description |
---|---|---|
System.Char | key | |
System.String | changedString | |
System.String | changedValueString |
Returns
Type |
---|
System.Boolean |
RaiseSetNull(Object)
Declaration
protected virtual bool RaiseSetNull(object nullValue)
Parameters
Type | Name | Description |
---|---|---|
System.Object | nullValue |
Returns
Type |
---|
System.Boolean |
RaiseValidationError(String, Int32)
This method raises the ValidationError event.
Declaration
protected void RaiseValidationError(string invalidText, int startPosition)
Parameters
Type | Name | Description |
---|---|---|
System.String | invalidText | The text that was input. |
System.Int32 | startPosition | The start position of the error. |
Remarks
See the OnValidationError(ValidationErrorArgs) method for more information.
RaiseValidationError(String, Int32, String)
Declaration
protected void RaiseValidationError(string invalidText, int startPosition, string errorMessage)
Parameters
Type | Name | Description |
---|---|---|
System.String | invalidText | |
System.Int32 | startPosition | |
System.String | errorMessage |
RefreshCulture()
Refreshes and reapplies the culture specific settings.
Declaration
public void RefreshCulture()
Remarks
Call this function when there has been a change in the CurrentCulture of the application.
RemoveFormatting(String)
Declaration
protected virtual string RemoveFormatting(string formattedText)
Parameters
Type | Name | Description |
---|---|---|
System.String | formattedText |
Returns
Type |
---|
System.String |
RemoveFormatting(String, Boolean)
Declaration
protected virtual string RemoveFormatting(string formattedText, bool padIfEmpty)
Parameters
Type | Name | Description |
---|---|---|
System.String | formattedText | |
System.Boolean | padIfEmpty |
Returns
Type |
---|
System.String |
RemoveFormatting(String, NumberFormatInfo)
Declaration
protected virtual string RemoveFormatting(string formattedText, NumberFormatInfo info)
Parameters
Type | Name | Description |
---|---|---|
System.String | formattedText | |
System.Globalization.NumberFormatInfo | info |
Returns
Type |
---|
System.String |
RemoveFormatting(String, NumberFormatInfo, Boolean)
Declaration
protected virtual string RemoveFormatting(string formattedText, NumberFormatInfo info, bool padIfEmpty)
Parameters
Type | Name | Description |
---|---|---|
System.String | formattedText | |
System.Globalization.NumberFormatInfo | info | |
System.Boolean | padIfEmpty |
Returns
Type |
---|
System.String |
ResetControlBackColor()
Resets the ControlBackColor property to its default value.
Declaration
public void ResetControlBackColor()
ResetForeColor()
Resets the System.Windows.Forms.Control.ForeColor property to its default value.
Declaration
public override void ResetForeColor()
ResetNegativeColor()
Resets NegativeColor property to default value.
Declaration
public void ResetNegativeColor()
ResetPositiveColor()
Resets ResetPositiveColor property to default value.
Declaration
public void ResetPositiveColor()
ResetReadOnlyBackColor()
Resets ReadOnlyBackColor property to default value.
Declaration
public virtual void ResetReadOnlyBackColor()
ResetRightToLeft()
Resets the System.Windows.Forms.Control.RightToLeft property to its default value.
Declaration
public override void ResetRightToLeft()
ResetZeroColor()
Resets ZeroColor property to default value.
Declaration
public void ResetZeroColor()
SelectAll()
Selects all text in the text box.
Declaration
public virtual void SelectAll()
Remarks
This method is called when the menu item "Select All" or its shortcut (CTRL+A) is used. This method overrides the base implementation in System.Windows.Forms.TextBoxBase.SelectAll. Override this method to provide your own implementation for SelectAll.
SetControlColor()
Sets the control's forecolor depending on whether the current value is negative.
Declaration
public void SetControlColor()
Remarks
See the NegativeColor and PositiveColor properties.
SetDefaultValue(Object)
Declaration
protected void SetDefaultValue(object defaultValue)
Parameters
Type | Name | Description |
---|---|---|
System.Object | defaultValue |
SetEmptySelection(Int32)
Sets the start position to value passed and sets the SelectionLength to be zero.
Declaration
public void SetEmptySelection(int selectionStart)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | selectionStart | The start of the selection. |
SetModifiedText(String, String)
Takes the incoming text, formats it based on the rules and settings prevailing currently and sets the display accordingly. Returns the length of the new text after setting the display.
Declaration
protected string SetModifiedText(string formattedText, string rawValue)
Parameters
Type | Name | Description |
---|---|---|
System.String | formattedText | |
System.String | rawValue |
Returns
Type |
---|
System.String |
SetNegativeInputPending(Boolean)
Declaration
protected void SetNegativeInputPending(bool negativeInputPending)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | negativeInputPending |
SetNullNumberValue()
Declaration
protected virtual void SetNullNumberValue()
SetPreserveData(Boolean)
Declaration
protected void SetPreserveData(bool preserveData)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | preserveData |
SetTextBoxText(String)
Declaration
protected void SetTextBoxText(string text)
Parameters
Type | Name | Description |
---|---|---|
System.String | text |
SetTextProperty(String)
Declaration
protected virtual void SetTextProperty(string newText)
Parameters
Type | Name | Description |
---|---|---|
System.String | newText |
SetValue(Object)
Declaration
protected virtual void SetValue(object val)
Parameters
Type | Name | Description |
---|---|---|
System.Object | val |
SetZeroNegative(Boolean)
Declaration
protected void SetZeroNegative(bool zeroNegative)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | zeroNegative |
ShouldSerializeNegativeColor()
Indicates whether NegativeColor property value should be serialized.
Declaration
public bool ShouldSerializeNegativeColor()
Returns
Type |
---|
System.Boolean |
ShouldSerializeNegativeSign()
Indicates whether the NegativeSign should not be serialized if the value is the same as the one for the current culture.
Declaration
protected bool ShouldSerializeNegativeSign()
Returns
Type | Description |
---|---|
System.Boolean | True if the property should be serialized; otherwise False. |
ShouldSerializePositiveColor()
Indicates whether PositiveColor property value should be serialized.
Declaration
public bool ShouldSerializePositiveColor()
Returns
Type |
---|
System.Boolean |
ShouldSerializeZeroColor()
Indicates whether ZeroColor property value should be serialized.
Declaration
public bool ShouldSerializeZeroColor()
Returns
Type |
---|
System.Boolean |
ToggleNegative(String)
Declaration
protected virtual string ToggleNegative(string currentText)
Parameters
Type | Name | Description |
---|---|---|
System.String | currentText |
Returns
Type |
---|
System.String |
Undo()
This method will Undo the previous operation.
Declaration
public virtual void Undo()
Remarks
This method is invoked when the Undo context menu item is clicked or the shortcut (CTRL+Z) is clicked. You can override this method to provide your own implementation for Undo.
Validate(Boolean)
Validates the control.
Declaration
public virtual bool Validate(bool bRaiseValidationError)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | bRaiseValidationError | Indicates whether the validation error is to be raised. |
Returns
Type |
---|
System.Boolean |
WndProc(ref Message)
Declaration
protected override void WndProc(ref Message m)
Parameters
Type | Name | Description |
---|---|---|
System.Windows.Forms.Message | m |
Overrides
Events
BindableValueChanged
Occurs when the BindableValue property is changed.
Declaration
public event EventHandler BindableValueChanged
Event Type
Type |
---|
System.EventHandler |
ClipTextChanged
Occurs when the DecimalValue property is changed.
Declaration
public event EventHandler ClipTextChanged
Event Type
Type |
---|
System.EventHandler |
ControlValidated
Occurs when the BindableValue property is changed.
Declaration
public event ControlValidatedEventHandler ControlValidated
Event Type
Type |
---|
ControlValidatedEventHandler |
FormattedTextChanged
Occurs when the DecimalValue property is changed.
Declaration
public event EventHandler FormattedTextChanged
Event Type
Type |
---|
System.EventHandler |
KeyValidate
Event raised when a Key is to be validated. This validation is performed before any of the NumberTextBox's own validation of the input character.
Declaration
public event KeyValidateEventHandler KeyValidate
Event Type
Type |
---|
KeyValidateEventHandler |
SetNull
Event raised when NULL State is to be set based on a value.
Declaration
public event SetNullEventHandler SetNull
Event Type
Type |
---|
SetNullEventHandler |
ValidationError
Occurs when the input text is invalid for the current state of the control.
Declaration
public event ValidationErrorEventHandler ValidationError
Event Type
Type |
---|
ValidationErrorEventHandler |
Remarks
This event can be handled and you can do your processing based on the information provided. The ValidationErrorEventArgs object will provide the invalid text that was input and also the position within that text where the error occurred.
The ValidationError event is raised when: 1. The System.Windows.Forms.Control.Validating event is raised (if there is invalid input). 2. Invalid key characters are input. 3. Invalid values are set through the Text property.
Examples
Console.WriteLine("ValidationError in currencyTextBox1 InvalidText" + e.InvalidText);
Console.WriteLine("ValidationError in currencyTextBox1 StartPosition" + e.StartPosition );