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

标签 c#

我有一个接受所有内容的文本框,但我只想接受日期,因为它的出生日期框我使用此代码作为字母和数字,但不知道如何使用这样的代码作为出生日期框

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

最佳答案

您可能需要一个屏蔽文本框,我不经常使用,但我认为这将是语法:

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

这将在加载表单时设置文本框的掩码,使用户只能输入日期。
希望我有所帮助。

关于c# - 如何使文本框仅接受出生日期格式c#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33834796/

相关文章:

C# Winforms Bind ListBox to DataTable问题

c# - 在此 LINQ 查询中 Any() 是什么意思?

C# 'SerialPort' 不包含采用 6 个参数的构造函数

c# - 有没有更好的方法来测量 CPU 性能而不影响性能?

c# - 使用数组和 redim 保护器关键字将 VB 代码转换为 C#

c# - WPF ListView 大数据时性能很差

c# - NAudio 将输入字节数组转换为 double 组

c# - MVC 4 Web Api 发布

c# - HttpClient 使用 JToken 和字符串发布 MultipartFormDataContent 返回 404 错误

c# - 什么决定了 C# 程序中的 .NET 日期格式?