简体   繁体   English

如何使文本框只接受出生日期格式 c#

[英]how to make a textbox accept only date of birth format c#

I got a text box that accepts everything but i want to accept only date because its Date of birth box i used this code for the letter and digit but don't know how to use something like this for date of birth box我有一个可以接受所有内容的文本框,但我只想接受日期,因为它的出生日期框我使用此代码作为字母和数字,但不知道如何使用这样的东西作为出生日期框

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");
    }

enter image description here在此处输入图片说明

You would probably need a Masked Text Box, I am not using that often but I think this would be the syntax:您可能需要一个蒙版文本框,我不经常使用它,但我认为这将是语法:

private void Form1_Load(object sender, EventArgs e)
{
    InitializeComponent();
    maskedTextBox1.Mask = "00/00/0000";
}

This would, when the form is loaded, set the mask of the TextBox that the user can only enter a date.这将在加载表单时设置用户只能输入日期的 TextBox 的掩码。
Hope I helped.希望我有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM