dateTimePicker ValueChange

时间:2013-12-29 03:23:15

标签: vb.net winforms

我有DateTimePicker,每次我都希望调用事件dtpJournalDate.ValueChanged

我的问题是,当我点击下拉箭头时,事件dtpJournalDate.ValueChange已经在执行,即使我还没有选择新的日期,在我选择了一个日期后,它会再次执行{{ 1}}事件。我只想在选择约会后执行事件ValueChange

ValueChange

2 个答案:

答案 0 :(得分:0)

使用CloseUp事件处理程序作为@Damith提到

Private Sub dtpJournalDate_CloseUp(sender As Object, e As EventArgs) Handles dtpParametersDate.CloseUp
    'Some Codes to do when changing the date
End Sub

但如果用户手动输入日期信息(直接写入DateTimePicker的文本框),此事件将不会触发。
然后,您可以添加KeyPress事件处理程序,并在用户按下Enter - 按钮后运行您的代码:

Private Sub dtpJournalDate_KeyPress(sender As Object, e As KeyPressEventArgs) Handles dtpParametersDate.KeyPress
    If e.KeyChar = Convert.ToChar(Keys.Enter) Then
        'Run your code with new date information
    End If
End Sub

答案 1 :(得分:0)

或者您可以在onCloseUp事件中更改事件处理程序

Private Sub MyDatetimePicker_ValueChanged(sender As Object, e As EventArgs) Handles Me.ValueChanged
        Me.OnCloseUp(e)
        'Do what ever change you want, when instance is created.
End Sub