可输入文本框在C#中被restriced到格式化的类型?文本框、类型、restriced

2023-09-07 08:34:08 作者:暴走の萝莉

我只是想知道,如果有一个函数/办法限制输入到textbot到格式化的类型如:一个用户只能输入日期类型转换为文本框;或类似的C扫描集,我可以使用以达到相同的功能的函数?

I'd just like to know if there's a function/way to restrict input to a textbot to a formatted type e.g. a user can only enter a date type into a textbox; or a function similar to to the C scanset that I can use to achieve the same functionality?

感谢

推荐答案

如果你正在写一个桌面应用程序,你可以使用MaskedTextBox.

If you are writing a desktop app you could use the MaskedTextBox.

本的MaskedTextBox类是增强型   支持TextBox控件   声明语法接受或   拒绝用户输入。使用面膜   属性,你可以指定   无需编写任何下列输入   在自定义的验证逻辑您   应用:

The MaskedTextBox class is an enhanced TextBox control that supports a declarative syntax for accepting or rejecting user input. Using the Mask property, you can specify the following input without writing any custom validation logic in your application:   

所需输入的字符。

Required input characters.

可选的输入字符。

输入预期在掩模的给定位置的类型;对于   例如,数字或字母或   字母数字字符。

The type of input expected at a given position in the mask; for example, a digit, or an alphabetic or alphanumeric character.

蒙版文字或字符应该直接出现在那   MaskedTextBox中;例如,   连字符( - )中的电话号码,或   在价格货币符号。

Mask literals, or characters that should appear directly in the MaskedTextBox; for example, the hyphens (-) in a phone number, or the currency symbol in a price.

特别处理输入的字符;例如,转换   字母为大写。

Special processing for input characters; for example, to convert alphabetic characters to uppercase.