不要忘记我唯一需要的是时间不是约会时间
我将datetimepicker(“hh:mm”)中的值保存到my.settings中。
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
My.Settings.firstStart = DateTimePicker1.Value.TimeOfDay
My.Settings.firstEnd = DateTimePicker2.Value.TimeOfDay
My.Settings.secondStart = DateTimePicker3.Value.TimeOfDay
My.Settings.secondEnd = DateTimePicker4.Value.TimeOfDay
My.Settings.Save()
End Sub
之后我将mysettings的值与当前时间进行比较
Private Sub timer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles timer.Tick
If My.Settings.firstStart <= currentTime AndAlso currentTime <= My.Settings.firstEnd Then
Label2.Text = "First Class"
ElseIf My.Settings.secondStart <= currentTime AndAlso currentTime <= My.Settings.secondEnd Then
Label2.Text = "Second Class"
Else
Label2.Text = "Free Time"
End If
End Sub
为什么label2.text即使在当前时间范围内(“第二类”)也不想改变
但是当我重新打开应用程序时,它将显示“Second Class”并且label2.text将不会改变,直到我下次重新打开应用程序,无论经过多长时间。
接下来我如何将my.settings中的数据加载到我的datetimepicker。 不要忘记唯一重要的是TIME不是日期我根本不需要使用日期
答案 0 :(得分:0)
将currentTime
的值设置为TimerTick
事件
Private Sub timer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles timer.Tick
TextBox1.Text = Date.Now.ToString("hh:mm")
Dim currentTime As TimeSpan = Date.Now.TimeOfDay
If My.Settings.firstStart <= currentTime AndAlso currentTime <= My.Settings.firstEnd Then
Label2.Text = "First Class"
ElseIf My.Settings.secondStart <= currentTime AndAlso currentTime <= My.Settings.secondEnd Then
Label2.Text = "Second Class"
Else
Label2.Text = "Free Time"
End If
End Sub