Skip to main content
All docs
V25.1
  • 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.1.dll

    NuGet Package: DevExpress.Win.Navigation

    Declaration

    public virtual void EnableCustomMaskTextInput(
        Action<CustomTextMaskInputArgs> onTextInput,
        object tag = null
    )

    Parameters

    Name Type Description
    onTextInput Action<CustomTextMaskInputArgs>

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

    Optional Parameters

    Name Type Default Description
    tag Object null

    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.

    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);
    });
    

    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