Form1 中
trackbar name:trkHour maximum: 23 minimum:0
textBox name:txtstate
Public Class Form1 Inherits System.Windows.Forms.Form Public Enum DayAction As Integer Asleep = 0 GettingReadyForWork = 1 TravelingToWork = 2 AtWork = 3 AtLunch = 4 TravelingFromWork = 5 RelaxingWithFriends = 6 GettingReadyForBed = 7 End Enum Public CurrentState As DayAction Public Property Hour() As Integer Get Return trkHour.Value End Get Set(ByVal Value As Integer) trkHour.Value = Value Dim hour As Integer = Value If hour >= 6 And hour < 7 Then CurrentState = DayAction.TravelingToWork ElseIf hour >= 7 And hour < 8 Then CurrentState = DayAction.TravelingToWork ElseIf hour >= 8 And hour < 13 Then CurrentState = DayAction.AtWork ElseIf hour >= 13 And hour < 14 Then CurrentState = DayAction.AtLunch ElseIf hour >= 14 And hour < 17 Then CurrentState = DayAction.AtWork ElseIf hour >= 17 And hour < 18 Then CurrentState = DayAction.TravelingFromWork ElseIf hour > 18 And hour < 22 Then CurrentState = DayAction.RelaxingWithFriends ElseIf hour >= 22 And hour < 23 Then CurrentState = DayAction.GettingReadyForBed Else CurrentState = DayAction.Asleep End If Dim statusText As String statusText = "at" & Value & ":00,Len is" & CurrentState.ToString() txtState.Text = statusText End Set End Property Private Sub Form1_Load(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles MyBase.Load Me.Hour = Date.Now.Hour End Sub Private Sub trkHour_Scroll(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles trkHour.Scroll Me.Hour = trkHour.Value End Sub End Class