晚上好。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属性的代码。所以当然你也可以添加语句来显示消息框。十分简单。 –