Back to Devexpress

RepositoryItemTextEdit.EnableCustomMaskTextInput(Action<CustomTextMaskInputArgs>, Object) Method

windowsforms-devexpress-dot-xtraeditors-dot-repository-dot-repositoryitemtextedit-dot-enablecustommasktextinput-x28-system-dot-action-devexpress-dot-data-dot-mask-dot-customtextmaskinputargs-system-dot-object-x29.md

latest4.3 KB
Original Source

RepositoryItemTextEdit.EnableCustomMaskTextInput(Action<CustomTextMaskInputArgs>, Object) Method

Allows you to manually control user edits, and modify them according to your custom logic.

Namespace : DevExpress.XtraEditors.Repository

Assembly : DevExpress.XtraEditors.v25.2.dll

NuGet Package : DevExpress.Win.Navigation

Declaration

csharp
public virtual void EnableCustomMaskTextInput(
    Action<CustomTextMaskInputArgs> onTextInput,
    object tag = null
)
vb
Public Overridable Sub EnableCustomMaskTextInput(
    onTextInput As Action(Of CustomTextMaskInputArgs),
    tag As Object = Nothing
)

Parameters

NameTypeDescription
onTextInputAction<CustomTextMaskInputArgs>

The Action of the CustomTextMaskInputArgs type that allows you to track and modify user changes, and set up final editor text.

|

Optional Parameters

NameTypeDefaultDescription
tagObjectnull

The tag passed to the Action (assigned to the CustomTextMaskInputArgs.Tag property). If not set, the BaseEdit.Tag property value is used.

|

Remarks

The code sample below illustrates how to enable users to enter only Latin letters, and automatically capitalize them. See this article for information on how to implement similar custom masks for multiple editors at once: How to: Manually Process User Input in Editors.

csharp
textEdit1.Properties.EnableCustomMaskTextInput(args => {
    // Do nothing if no edits were made
    if (args.IsCanceled || args.ActionType == CustomTextMaskInputAction.Init)
        return;
    // Accept only letters
    if (!Regex.IsMatch(args.InsertedText, @"^[a-zA-Z]+$")) {
        args.Cancel();
        return;
    }
    var textInfo = CultureInfo.InvariantCulture.TextInfo;
    // Capitalize the editor text and set it as the final value
    args.SetResult(textInfo.ToUpper(args.ResultEditText), args.ResultCursorPosition, args.ResultSelectionAnchor);
});
vb
textEdit1.Properties.EnableCustomMaskTextInput(Sub(args)
    ' Do nothing if no edits were made
    If args.IsCanceled OrElse args.ActionType = CustomTextMaskInputAction.Init Then
        Return
    End If
    ' Accept only letters
    If Not Regex.IsMatch(args.InsertedText, "^[a-zA-Z]+$") Then
        args.Cancel()
        Return
    End If
    Dim textInfo = CultureInfo.InvariantCulture.TextInfo
    ' Capitalize the editor text and set it as the final value
    args.SetResult(textInfo.ToUpper(args.ResultEditText), args.ResultCursorPosition, args.ResultSelectionAnchor)
End Sub)

Compared to the RepositoryItem.EditValueChanging event, which also allows you to track user changes, the EnableCustomMaskTextInput method offers a wider set of tools to manually control what is happening with an editor. The EditValueChanging event does not allow you to identify the type of a user edit, and has no API to locate and change cursor position and selection anchor.

See Also

RepositoryItemTextEdit Class

RepositoryItemTextEdit Members

DevExpress.XtraEditors.Repository Namespace