MaskedTextProvider 类

定义

表示可由支持掩码的任何数量的控件(如 MaskedTextBox 控件)使用的掩码分析服务。Represents a mask-parsing service that can be used by any number of controls that support masking, such as the MaskedTextBox control.

public ref class MaskedTextProvider : ICloneable
public class MaskedTextProvider : ICloneable
type MaskedTextProvider = class
    interface ICloneable
Public Class MaskedTextProvider
Implements ICloneable
继承
MaskedTextProvider
实现

注解

MaskedTextBox 控件包含由文本字符和格式设置元素组成的掩码,它对所有用户输入进行测试。The MaskedTextBox control contains a mask, composed of literal characters and formatting elements, that it tests all user input against. Windows 窗体将特定掩码分析引擎与 MaskedTextBox永久关联,而不是将其作为单独的服务提供,该服务由 MaskedTextProvider 类表示,该服务定义了 Mask 属性文档中讨论的掩码语言的语法。Instead of permanently associating a specific mask-parsing engine with MaskedTextBox, Windows Forms provides it as a separate service, represented by the MaskedTextProvider class, which defines the syntax of the masking language discussed in the documentation for the Mask property.

MaskedTextBox 类的许多成员将其实现方式称为关联的 MaskedTextProvider的与命名相同的成员。Many of the members of the MaskedTextBox class refer their implementation to similarly named members of the associated MaskedTextProvider. 例如,MaskedTextBox 类的 MaskedTextBox.PromptChar 属性引用对 MaskedTextProvider 类的 PromptChar 的所有访问。For example, the MaskedTextBox.PromptChar property of the MaskedTextBox class refers all access to the PromptChar of the MaskedTextProvider class.

MaskedTextProvider 所使用的掩码分析引擎在 Microsoft Visual Basic 版本6中包含的掩码编辑控件之后建模。The mask-parsing engine used by MaskedTextProvider is modeled after the Masked Edit control included in Microsoft Visual Basic version 6. 它的掩码语言在 Mask 属性的文档中进行了介绍。Its masking language is described in the documentation for the Mask property.

MaskedTextProvider 类涉及以下三个不同的字符串。The following three distinct strings are involved with the MaskedTextProvider class.

字符串名称String name 说明Description
输入字符或字符串Input character or string 表示用作应用掩码的输入的字符。Represents the characters used as input that the mask is applied against. 在实际情况下,输入字符串可能由多个输入操作组成,其中包括 AddReplaceInsertAtRemoveIn actuality, the input string may be composed of multiple input operations, including Add, Replace, InsertAt, and Remove. 因此,不能直接访问输入字符串。Therefore, the input string cannot be accessed directly. 但是,通过 AllowPromptAsInputAsciiOnlyResetOnPromptResetOnSpace 属性提供输入字符串处理的各个方面。However, aspects of the input string handling are available though the AllowPromptAsInput and AsciiOnly, ResetOnPrompt, and ResetOnSpace properties.
掩码Mask 表示用于将输入字符串转换为带格式字符串的输入格式掩码。Represents the input formatting mask used to transform the input string into the formatted string. 此字符串在 MaskedTextProvider 中设置,主要通过 Mask 属性进行访问。This string is set in the MaskedTextProvider and accessed primarily though the Mask property. 还可以通过其他成员(例如 LengthPasswordCharPromptChar 属性)使用掩码的特征。Characteristics of the mask are also available through other members, such as the Length, PasswordChar, and PromptChar properties.
格式化字符串Formatted string 表示在将完整的掩码应用于输入字符串时所产生的字符串。Represents the string that results when the full mask is applied to the input string. 可以通过类的多个成员查询带格式的字符串,包括 Item[Int32]LengthLastAssignedPositionMaskFullMaskCompletedFindEditPositionFrom等。The formatted string can be queried with many members of the class, including Item[Int32], Length, LastAssignedPosition, MaskFull, MaskCompleted, FindEditPositionFrom, and so on. 带格式字符串的完整值可从 ToDisplayStringToString 方法中获取。The full value of the formatted string is available from the ToDisplayString and ToString methods.

备注

输入字符串可以表示直接用户输入(如 MaskedTextBox的情况),也可以由不与用户输入/输出操作直接关联的其他进程生成。The input string may represent direct user input, as in the case of the MaskedTextBox, or may be generated by other processes not directly associated with user input/output operations.

构造函数

MaskedTextProvider(String)

使用指定的掩码初始化 MaskedTextProvider 类的新实例。Initializes a new instance of the MaskedTextProvider class using the specified mask.

MaskedTextProvider(String, Boolean)

使用指定的掩码和 ASCII 限制值初始化 MaskedTextProvider 类的新实例。Initializes a new instance of the MaskedTextProvider class using the specified mask and ASCII restriction value.

MaskedTextProvider(String, Char, Boolean)

使用指定的掩码、密码字符和用法提示值初始化 MaskedTextProvider 类的新实例。Initializes a new instance of the MaskedTextProvider class using the specified mask, password character, and prompt usage value.

MaskedTextProvider(String, CultureInfo)

使用指定的掩码和区域性初始化 MaskedTextProvider 类的新实例。Initializes a new instance of the MaskedTextProvider class using the specified mask and culture.

MaskedTextProvider(String, CultureInfo, Boolean)

使用指定的掩码、区域性和 ASCII 限制值初始化 MaskedTextProvider 类的新实例。Initializes a new instance of the MaskedTextProvider class using the specified mask, culture, and ASCII restriction value.

MaskedTextProvider(String, CultureInfo, Boolean, Char, Char, Boolean)

使用指定的掩码、区域性、用法提示值、提示字符、密码字符和 ASCII 限制值初始化 MaskedTextProvider 类的新实例。Initializes a new instance of the MaskedTextProvider class using the specified mask, culture, prompt usage value, prompt character, password character, and ASCII restriction value.

MaskedTextProvider(String, CultureInfo, Char, Boolean)

使用指定的掩码、区域性、密码字符和用法提示值初始化 MaskedTextProvider 类的新实例。Initializes a new instance of the MaskedTextProvider class using the specified mask, culture, password character, and prompt usage value.

属性

AllowPromptAsInput

获取一个值,该值指示是否应将提示字符视为有效的输入字符。Gets a value indicating whether the prompt character should be treated as a valid input character or not.

AsciiOnly

获取一个值,指示掩码是否接受 ASCII 字符集之外的字符。Gets a value indicating whether the mask accepts characters outside of the ASCII character set.

AssignedEditPositionCount

获取已成功赋予输入值的可编辑字符位置的数目。Gets the number of editable character positions that have already been successfully assigned an input value.

AvailableEditPositionCount

获取输入掩码中尚未赋予输入值的可编辑字符位置的数目。Gets the number of editable character positions in the input mask that have not yet been assigned an input value.

Culture

获取输入掩码中确定可本地化的分隔符和占位符的值的区域性。Gets the culture that determines the value of the localizable separators and placeholders in the input mask.

DefaultPasswordChar

获取用于遮盖用户输入的默认密码字符。Gets the default password character used obscure user input.

EditPositionCount

获取带格式字符串中的可编辑位置数。Gets the number of editable positions in the formatted string.

EditPositions

获取为带格式字符串中的可编辑位置新创建的枚举数。Gets a newly created enumerator for the editable positions in the formatted string.

IncludeLiterals

获取或设置一个值,该值指示输入掩码中的原义字符是否应包含在带格式的字符串中。Gets or sets a value that indicates whether literal characters in the input mask should be included in the formatted string.

IncludePrompt

获取或设置一个值,该值指示当显示带格式的字符串时是否使用 PromptChar 来表示缺少的用户输入。Gets or sets a value indicating whether PromptChar is used to represent the absence of user input when displaying the formatted string.

InvalidIndex

获取无效索引范围的上限。Gets the upper bound of the range of invalid indexes.

IsPassword

获取或设置一个值,该值确定是否应将密码保护应用于带格式的字符串。Gets or sets a value that determines whether password protection should be applied to the formatted string.

Item[Int32]

获取带格式字符串中位于指定位置的元素。Gets the element at the specified position in the formatted string.

LastAssignedPosition

获取已赋给掩码的最靠右的输入字符在掩码中的索引。Gets the index in the mask of the rightmost input character that has been assigned to the mask.

Length

获取掩码的长度,不包括任何掩码修饰符字符。Gets the length of the mask, absent any mask modifier characters.

Mask

获取输入掩码。Gets the input mask.

MaskCompleted

获取一个值,该值指示是否所有必需的输入均已输入到带格式的字符串中。Gets a value indicating whether all required inputs have been entered into the formatted string.

MaskFull

获取一个值,该值指示是否所有必需和可选的输入均已输入到带格式的字符串中。Gets a value indicating whether all required and optional inputs have been entered into the formatted string.

PasswordChar

获取或设置要替代实际输入字符的字符。Gets or sets the character to be substituted for the actual input characters.

PromptChar

为所有可用的编辑位置获取或设置用于表示缺少用户输入的字符。Gets or sets the character used to represent the absence of user input for all available edit positions.

ResetOnPrompt

获取或设置一个值,该值确定应如何处理与提示字符匹配的输入字符。Gets or sets a value that determines how an input character that matches the prompt character should be handled.

ResetOnSpace

获取或设置一个值,该值确定应如何处理空白输入字符。Gets or sets a value that determines how a space input character should be handled.

SkipLiterals

获取或设置一个值,该值指示掩码中的原义字符位置是否可由其相同的值覆盖。Gets or sets a value indicating whether literal character positions in the mask can be overwritten by their same values.

方法

Add(Char)

将指定的输入字符添加到带格式字符串的末尾。Adds the specified input character to the end of the formatted string.

Add(Char, Int32, MaskedTextResultHint)

将指定输入字符添加到带格式字符串的末尾,然后输出位置和描述性信息。Adds the specified input character to the end of the formatted string, and then outputs position and descriptive information.

Add(String)

将指定输入字符串中的字符添加到带格式字符串的末尾。Adds the characters in the specified input string to the end of the formatted string.

Add(String, Int32, MaskedTextResultHint)

将指定的输入字符串中的字符添加到带格式字符串的末尾,然后输出位置和描述性信息。Adds the characters in the specified input string to the end of the formatted string, and then outputs position and descriptive information.

Clear()

通过用提示字符替换可编辑输入字符,从带格式字符串中清除所有可编辑输入字符。Clears all the editable input characters from the formatted string, replacing them with prompt characters.

Clear(MaskedTextResultHint)

通过用提示字符替换可编辑输入字符,从带格式字符串中清除所有可编辑输入字符,然后输出描述性信息。Clears all the editable input characters from the formatted string, replacing them with prompt characters, and then outputs descriptive information.

Clone()

创建当前 MaskedTextProvider 的副本。Creates a copy of the current MaskedTextProvider.

Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
FindAssignedEditPositionFrom(Int32, Boolean)

使用指定的搜索方向,返回指定位置之后第一个已赋值的可编辑位置的位置。Returns the position of the first assigned editable position after the specified position using the specified search direction.

FindAssignedEditPositionInRange(Int32, Int32, Boolean)

使用指定的搜索方向,返回指定位置之间第一个赋值可编辑位置的位置。Returns the position of the first assigned editable position between the specified positions using the specified search direction.

FindEditPositionFrom(Int32, Boolean)

使用指定的搜索方向,返回指定位置之后第一个可编辑位置的位置。Returns the position of the first editable position after the specified position using the specified search direction.

FindEditPositionInRange(Int32, Int32, Boolean)

使用指定的搜索方向,返回指定位置之间第一个可编辑位置的位置。Returns the position of the first editable position between the specified positions using the specified search direction.

FindNonEditPositionFrom(Int32, Boolean)

使用指定的搜索方向,返回指定位置之后第一个不可编辑位置的位置。Returns the position of the first non-editable position after the specified position using the specified search direction.

FindNonEditPositionInRange(Int32, Int32, Boolean)

使用指定的搜索方向,返回指定位置之间第一个不可编辑位置的位置。Returns the position of the first non-editable position between the specified positions using the specified search direction.

FindUnassignedEditPositionFrom(Int32, Boolean)

使用指定的搜索方向,返回指定位置之后第一个未赋值可编辑位置的位置。Returns the position of the first unassigned editable position after the specified position using the specified search direction.

FindUnassignedEditPositionInRange(Int32, Int32, Boolean)

使用指定的搜索方向,返回指定位置之间第一个未赋值可编辑位置的位置。Returns the position of the first unassigned editable position between the specified positions using the specified search direction.

GetHashCode()

用作默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetOperationResultFromHint(MaskedTextResultHint)

确定指定的 MaskedTextResultHint 表示成功还是失败。Determines whether the specified MaskedTextResultHint denotes success or failure.

GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
InsertAt(Char, Int32)

在带格式字符串中的指定位置插入指定字符。Inserts the specified character at the specified position within the formatted string.

InsertAt(Char, Int32, Int32, MaskedTextResultHint)

在带格式字符串中的指定位置插入指定的字符,同时返回最后一个插入位置和操作的状态。Inserts the specified character at the specified position within the formatted string, returning the last insertion position and the status of the operation.

InsertAt(String, Int32)

在带格式字符串中的指定位置插入指定的字符串。Inserts the specified string at a specified position within the formatted string.

InsertAt(String, Int32, Int32, MaskedTextResultHint)

将指定的字符串插入到带格式字符串中的指定位置,同时返回最后一个插入位置和操作的状态。Inserts the specified string at a specified position within the formatted string, returning the last insertion position and the status of the operation.

IsAvailablePosition(Int32)

确定指定位置是否可赋值。Determines whether the specified position is available for assignment.

IsEditPosition(Int32)

确定指定的位置是否为可编辑。Determines whether the specified position is editable.

IsValidInputChar(Char)

确定指定的字符是否为有效的输入字符。Determines whether the specified character is a valid input character.

IsValidMaskChar(Char)

确定指定的字符是否为有效的掩码字符。Determines whether the specified character is a valid mask character.

IsValidPasswordChar(Char)

确定指定的字符是否为有效的密码字符。Determines whether the specified character is a valid password character.

MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
Remove()

从带格式的字符串中移除最后一个赋值的字符。Removes the last assigned character from the formatted string.

Remove(Int32, MaskedTextResultHint)

从带格式字符串中移除最后一个赋值的字符,然后输出移除位置和描述性信息。Removes the last assigned character from the formatted string, and then outputs the removal position and descriptive information.

RemoveAt(Int32)

从带格式的字符串中移除位于指定位置的赋值字符。Removes the assigned character at the specified position from the formatted string.

RemoveAt(Int32, Int32)

从带格式的字符串中移除指定位置之间的赋值的字符。Removes the assigned characters between the specified positions from the formatted string.

RemoveAt(Int32, Int32, Int32, MaskedTextResultHint)

从带格式的字符串中移除指定位置之间的赋值的字符,然后输出移除位置和描述性信息。Removes the assigned characters between the specified positions from the formatted string, and then outputs the removal position and descriptive information.

Replace(Char, Int32)

用指定的字符值替换指定位置或指定位置后面的单个字符。Replaces a single character at or beyond the specified position with the specified character value.

Replace(Char, Int32, Int32, Int32, MaskedTextResultHint)

在指定的开始和结束位置之间使用指定的字符值替换单个字符,然后输出移除位置和描述性信息。Replaces a single character between the specified starting and ending positions with the specified character value, and then outputs the removal position and descriptive information.

Replace(Char, Int32, Int32, MaskedTextResultHint)

用指定的字符值替换指定位置或指定位置后面的单个字符,然后输出移除位置和描述性信息。Replaces a single character at or beyond the specified position with the specified character value, and then outputs the removal position and descriptive information.

Replace(String, Int32)

从指定位置开始使用指定字符串替换一定范围的可编辑字符。Replaces a range of editable characters starting at the specified position with the specified string.

Replace(String, Int32, Int32, Int32, MaskedTextResultHint)

在指定的开始位置和结束位置之间的范围内使用指定的字符串替换可编辑字符,然后输出移除位置和描述性信息。Replaces a range of editable characters between the specified starting and ending positions with the specified string, and then outputs the removal position and descriptive information.

Replace(String, Int32, Int32, MaskedTextResultHint)

从指定位置开始使用指定字符串替换一定范围的可编辑字符,然后输出移除位置和描述性信息。Replaces a range of editable characters starting at the specified position with the specified string, and then outputs the removal position and descriptive information.

Set(String)

将带格式的字符串设置为指定的输入字符串。Sets the formatted string to the specified input string.

Set(String, Int32, MaskedTextResultHint)

将带格式的字符串设置为指定的输入字符串,然后输出移除位置和描述性信息。Sets the formatted string to the specified input string, and then outputs the removal position and descriptive information.

ToDisplayString()

以可显示的形式返回带格式字符串。Returns the formatted string in a displayable form.

ToString()

返回包含所有赋值的字符值的带格式字符串。Returns the formatted string that includes all the assigned character values.

ToString(Boolean)

返回带格式的字符串,还可以选择包含密码字符。Returns the formatted string, optionally including password characters.

ToString(Boolean, Boolean)

返回带格式的字符串,还可以选择包含提示字符和原义字符。Returns the formatted string, optionally including prompt and literal characters.

ToString(Boolean, Boolean, Boolean, Int32, Int32)

返回带格式字符串的子字符串,可以选择包含提示字符、原义字符和密码字符。Returns a substring of the formatted string, optionally including prompt, literal, and password characters.

ToString(Boolean, Boolean, Int32, Int32)

返回带格式字符串的子字符串,也可以选择包含提示字符和原义字符。Returns a substring of the formatted string, optionally including prompt and literal characters.

ToString(Boolean, Int32, Int32)

返回带格式字符串的子字符串,也可以选择包含密码字符。Returns a substring of the formatted string, optionally including password characters.

ToString(Int32, Int32)

返回带格式字符串的子字符串。Returns a substring of the formatted string.

VerifyChar(Char, Int32, MaskedTextResultHint)

测试指定的字符是否可以在指定位置成功设置。Tests whether the specified character could be set successfully at the specified position.

VerifyEscapeChar(Char, Int32)

测试指定的字符是否将在指定位置转义。Tests whether the specified character would be escaped at the specified position.

VerifyString(String)

测试指定的字符串是否可以成功设置。Tests whether the specified string could be set successfully.

VerifyString(String, Int32, MaskedTextResultHint)

测试指定的字符串是否可以成功设置,然后输出位置和描述性信息。Tests whether the specified string could be set successfully, and then outputs position and descriptive information.

适用于

另请参阅