我在Visual Studio VB中编写了一个应用程序来绘制一些数据作为日期的函数。在图表附近,我有一个DateTimePIcker,可以在图表上移动标记线。
基本上它可以工作,但当我点击按钮"上移"或者向下移动"在DateTimePicker上,分钟值超过59,该对象不会自动更新小时值。它提前1小时再次启动。
我尝试搜索某些内容或某些选项来修复此错误,但我没有找到任何内容。
任何人都可以帮助我吗?
提前谢谢你。
答案 0 :(得分:0)
即使您单击向下移动,也可以使用类似的代码:
Private intHours As Integer = 0
Private intMinutes As Integer = 0
Private Sub DateTimePicker1_ValueChanged(sender As System.Object, e As System.EventArgs) Handles DateTimePicker1.ValueChanged
Dim intOldHours As Integer = Me.intHours
Dim intOldMinutes As Integer = Me.intMinutes
Me.intHours = Me.DateTimePicker1.Value.Hour
Me.intMinutes = Me.DateTimePicker1.Value.Minute
If intOldHours = Me.intHours Then
If intOldMinutes = 59 AndAlso Me.intMinutes = 0 Then
Me.DateTimePicker1.Value = Me.DateTimePicker1.Value.AddHours(1)
ElseIf intOldMinutes = 0 AndAlso Me.intMinutes = 59 Then
Me.DateTimePicker1.Value = Me.DateTimePicker1.Value.AddHours(-1)
End If
End If
End Sub