我有一个接受所有内容的文本框,但我只想接受日期,因为它的出生日期框我使用此代码作为字母和数字,但不知道如何使用这样的代码作为出生日期框
private void SurmaneTextBox_KeyPress(object sender, KeyPressEventArgs e)
{
if (Char.IsControl(e.KeyChar) != true && Char.IsLetter(e.KeyChar) != true && !char.IsWhiteSpace(e.KeyChar))
{
e.Handled = true;
MessageBox.Show("Your only allowed to enter letters, Please enter only letters e.g Smith");
}
最佳答案
您可能需要一个屏蔽文本框,我不经常使用,但我认为这将是语法:
private void Form1_Load(object sender, EventArgs e)
{
InitializeComponent();
maskedTextBox1.Mask = "00/00/0000";
}
这将在加载表单时设置文本框的掩码,使用户只能输入日期。
希望我有所帮助。
关于c# - 如何使文本框仅接受出生日期格式c#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33834796/