DateTimePicker 不显示数据,即使我点击了要显示的日期
DateTimePicker does not displaying data even after I clicked a date to display
我的 WinForm 上有一个启用了 CheckBox 属性 的 DateTimePicker 控件。
在运行时,当我想要 select 一个日期时,它没有在 datetimepicker 文本框中显示它,我知道我的代码是正确的,因为相同的代码在我拥有的另一种形式上工作,但在这个形式中没有!
下面是我的代码的快照,如有任何帮助,我们将不胜感激:
Private Sub btnInsert_Click(sender As Object, e As EventArgs) Handles btnInsert.Click
DateTimePicker1.Enabled = True
DateTimerPicker1.Checked = False
If DateTimePicker1.Checked = False Then
DateTimePicker1.CustomFormat = " "
DateTimePicker1.Format = DateTimePickerFormat.Custom
Else
DateTimePicker1.Format = DateTimePickerFormat.Short
End If
End Sub
要处理该复选框的更改,您可以使用 ValueChanged
事件:
Private Sub DateTimePicker1_ValueChanged(sender As Object, e As EventArgs) _
Handles DateTimePicker1.ValueChanged
If Me.DateTimePicker1.Checked=True Then
Me.DateTimePicker1.Format = DateTimePickerFormat.Short
Else
Me.DateTimePicker1.Format = DateTimePickerFormat.Custom
Me.DateTimePicker1.CustomFormat = " "
End If
End Sub
在您的代码中,您告诉它不要使用 DateTimePicker1.CustomFormat = " "
显示日期。
在下面查看我添加到您的代码中的注释:
DateTimerPicker1.Checked = False '<==== You set Checked to false
If DateTimePicker1.Checked = False Then '<==== You told if not checked (it's not checked)
DateTimePicker1.CustomFormat = " " '<==== Show space
DateTimePicker1.Format = DateTimePickerFormat.Custom
....
我的 WinForm 上有一个启用了 CheckBox 属性 的 DateTimePicker 控件。 在运行时,当我想要 select 一个日期时,它没有在 datetimepicker 文本框中显示它,我知道我的代码是正确的,因为相同的代码在我拥有的另一种形式上工作,但在这个形式中没有!
下面是我的代码的快照,如有任何帮助,我们将不胜感激:
Private Sub btnInsert_Click(sender As Object, e As EventArgs) Handles btnInsert.Click
DateTimePicker1.Enabled = True
DateTimerPicker1.Checked = False
If DateTimePicker1.Checked = False Then
DateTimePicker1.CustomFormat = " "
DateTimePicker1.Format = DateTimePickerFormat.Custom
Else
DateTimePicker1.Format = DateTimePickerFormat.Short
End If
End Sub
要处理该复选框的更改,您可以使用 ValueChanged
事件:
Private Sub DateTimePicker1_ValueChanged(sender As Object, e As EventArgs) _
Handles DateTimePicker1.ValueChanged
If Me.DateTimePicker1.Checked=True Then
Me.DateTimePicker1.Format = DateTimePickerFormat.Short
Else
Me.DateTimePicker1.Format = DateTimePickerFormat.Custom
Me.DateTimePicker1.CustomFormat = " "
End If
End Sub
在您的代码中,您告诉它不要使用 DateTimePicker1.CustomFormat = " "
显示日期。
在下面查看我添加到您的代码中的注释:
DateTimerPicker1.Checked = False '<==== You set Checked to false
If DateTimePicker1.Checked = False Then '<==== You told if not checked (it's not checked)
DateTimePicker1.CustomFormat = " " '<==== Show space
DateTimePicker1.Format = DateTimePickerFormat.Custom
....