using System.Configuration;
using System.Text;
using System.Windows.Forms;
namespace Test
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
// Initialize the masked text box.
var maskedTextBox1 = new MaskedTextBox
{
Location = new System.Drawing.Point(10, 10)
};
Controls.Add(maskedTextBox1);
// Read the static number from the configuration file.
var number = int.Parse(ConfigurationManager.AppSettings["number"]);
// Split the number into individual characters and escape them.
var prefix = new StringBuilder();
foreach (var character in number.ToString())
{
prefix.Append(@"\");
prefix.Append(character);
}
// Set the updated mask.
maskedTextBox1.Mask = prefix + "/00/00";
}
}
}
1条答案
按热度按时间zaqlnxep1#
您需要使用反斜杠转义掩码静态部分中的每个字符。参见文档中的备注。
\转义掩码字符,将其转换为文本。“\”是反斜杠的转义序列。
在这种情况下,掩码将如下所示:
可以通过编程方式转义字符。假设您有以下配置文件,其中包含掩码的静态部分。
然后可以按如下方式转义字符: