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
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
public virtual void EnableCustomMaskTextInput(
Action<CustomTextMaskInputArgs> onTextInput,
object tag = null
)
Public Overridable Sub EnableCustomMaskTextInput(
onTextInput As Action(Of CustomTextMaskInputArgs),
tag As Object = Nothing
)
| 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.
|
| 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.
|
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);
});
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