VB.net的DateTimePicker验证

时间:2016-05-15 09:07:13

标签: vb.net winforms validation datetime

我试图这样做:

If DateTimePicker1.Value.Date = DateTimePicker1.Value.Date Then
        MessageBox.Show("You have not entered a date of birth yet.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
        Exit Sub
    End If

虽然我的DateTimePicker值为2016-01-01,但在通过所有验证检查时,即使我更改了日期的值,上面的错误仍会显示。

这是怎么发生的?

1 个答案:

答案 0 :(得分:1)

    If DateTimePicker1.Value.Date = New Date(2016, 1, 1) Then
        MessageBox.Show("You have not entered a date of birth yet.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
        Exit Sub
    End If