DateTimeMaskedTextProvider
Since v2.12Masked text provider that edits a DateTime value using a fixed, culture-aware date and/or time format.
Remarks: This provider encapsulates all of the date/time masking, parsing, clamping, and stepping logic so it can be used with either a MaskedTextStepper<T> or a MaskedTextBox<T>. For a stepper, the GetStepValue(int, int, int) helper can be used from TextStepper's step handling to increment or decrement the segment at the caret. For a text box, simply assigning the provider gives masked, culture-aware date entry without stepping. The DateTimeMaskedTextStepper control wraps this provider with the appropriate control configuration.
Constructors
DateTimeMaskedTextProvider
#public DateTimeMaskedTextProvider(DateTimePickerMode mode = DateTimePickerMode.Date, CultureInfo culture = null)
Initializes a new instance of the DateTimeMaskedTextProvider class.
Parameters:
| mode (DateTimePickerMode = DateTimePickerMode.Date) | Date and/or time editing mode. |
| culture (CultureInfo = null) | Culture to use for the format and separators. Defaults to CultureInfo.CurrentCulture. |
Properties
EditPositions
#Gets an enumeration of all valid edit positions in the mask.
Value: The valid edit positions.
Implements: EditPositions
IsEmpty
#Gets a value indicating the mask is empty with no characters filled out.
Value:
true if the mask value is empty; otherwise, false.Implements: IsEmpty
MaskCompleted
#Gets a value indicating whether the mask has all required text to pass its validation.
Value:
true if mask is completed; otherwise, false.Implements: MaskCompleted
Text
#Gets or sets the text, usually excluding prompt or literal characters depending on the mask provider.
Methods
Clamp
#Parameters:
| value (DateTime?) | Value to clamp, or null. |
Returns: The clamped value, or
null if value is null.Clear
#Called to clear a range of characters at the specified position in the masked text.
Remarks: The cleared characters usually show the prompt character after cleared. This is useful for fixed length mask providers. For variable length, this is usually the same as calling IMaskedTextProvider.Delete(int, int, bool).
Parameters:
| position (ref int) | Position to clear at. |
| length (int) | Length of text (in the mask) to clear |
| forward (bool) | true to delete the text forward, or false to delete backward |
Returns:
true when the deletion was successful, or false if it failed.Implements: Clear
public void CommitText()
Called to update the display text after changes to the mask value.
Remarks: This is called after user changes to the mask value is complete, such as when the control loses focus, or when the user presses enter. This allows the mask provider to update the display text after changes are made to the value, while still allowing the user to type in the text without it changing until they are done.
Implements: CommitText
Delete
#Called to delete a range of characters at the specified position in the masked text.
GetStepValue
#Computes the value after stepping the segment at the specified caret index up or down.
Remarks: This is intended to be called from a stepper's step handling. When there is no current value, the current date/time (clamped to the allowed range) is used as a starting point.
Parameters:
| caretIndex (int) | Caret index used to determine which segment to step. |
| delta (int) | Amount to step, typically 1 for up or -1 for down. |
| segmentStart (out int) | Outputs the start index of the segment that was stepped, for re-selecting the range. |
Returns: The new value after stepping.
Insert
#Called to insert a character at the specified position in the masked text.
Returns:
true when the insertion was successful, or false if it failed.Implements: Insert