晚上好。VB.NET中ProgressBar特定百分比的事件
我想知道是否可以在進度條達到特定百分比時觸發事件。
例如:一旦進度條達到其值的90%,它將觸發一個消息框彈出。我使用ProgressBar比較兩次彼此。我可以在DateTimePicker中輸入一個時間,並將其與本地桌面時間進行比較。我點擊一個按鈕,將啓用定時器並開始比較這些時間。由於我比較時間,最小值和最大值總是不同,所以每次進度條達到90%時如何觸發事件?
正如你可能已經注意到,英語不是我的主要語言,所以它會更容易使用代碼來理解我現在使用:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
ProgressBar1.Minimum = 0
ProgressBar1.Maximum = GetTimeDifference(DateTimePicker1.Value, DateTime.Now)
Timer1.Start()
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim value As Integer = ProgressBar1.Maximum - GetTimeDifference(DateTimePicker1.Value, DateTime.Now)
If value > ProgressBar1.Maximum Then
Timer1.Stop()
Exit Sub
End If
ProgressBar1.Value = value
End Sub
Public Function GetTimeDifference(ByVal EndTime As DateTime, ByVal StartTime As DateTime) As Integer
Dim span As TimeSpan = EndTime.TimeOfDay - StartTime.TimeOfDay
Dim result As Integer = CInt(span.TotalSeconds)
Return result
End Function
感謝, 的Jordy。
這是你的設置Value屬性的代碼。所以當然你也可以添加語句來顯示消息框。十分簡單。 –