我已經獲得進度條填充,並且一旦StartTime已經到達進度條和標籤,告訴%工作。 我不能讓另一個按鈕說「停止」的昏暗的定時器是不允許我從目前的功能外調用它CountDown計時器不停止
尋找任何建議,使其停止。 我用盡有它包含如果
ProgressBar1.Value = Maximum then Timer.Stop() End if
但計時器將繼續滴答作響,並不會停止。
Imports System.Threading
Imports System.Windows.Threading.DispatcherTimer
Imports System.Timers
Imports System.Math
Class MainWindow
Private Sub Rectangle_MouseLeftButtonDown(sender As Object, e As MouseButtonEventArgs)
Me.DragMove()
End Sub
Private Sub button_Click(sender As Object, e As RoutedEventArgs)
Me.Close()
End Sub
Private Sub ext_button_Click(sender As Object, e As RoutedEventArgs) Handles ext_button.Click
Me.Close()
End Sub
Private Sub Window_Loaded(sender As Object, e As RoutedEventArgs)
Dim dispatcherTimer = New Threading.DispatcherTimer()
End Sub
Private Sub Timer_Tick(ByVal sender As Object, ByVal e As EventArgs)
Dim StartTime = (Convert.ToInt32(TextBoxHour1.Text) * 3600 + Convert.ToInt32(TextBoxMinute1.Text) * 60 + Convert.ToInt32(TextBoxSecond1.Text))
LabelST.Content = "Starting Seconds: " + Convert.ToString(StartTime)
LabelST2.Content = ProgressBar1.Value
ProgressBar1.Value = ProgressBar1.Value + 1
Dim percent As Int32 = Convert.ToString(ProgressBar1.Value/StartTime * 100)
LabelPercent1.Content = Convert.ToString(Math.Floor(percent)) + "%"
' Forcing the CommandManager to raise the RequerySuggested event
CommandManager.InvalidateRequerySuggested()
End Sub
Private Sub ButtonStart_Click(sender As Object, e As RoutedEventArgs) Handles ButtonStart.Click
Dim Timer = New Threading.DispatcherTimer()
Dim StartTime = (Convert.ToInt32(TextBoxHour1.Text) * 3600 + Convert.ToInt32(TextBoxMinute1.Text) * 60 + Convert.ToInt32(TextBoxSecond1.Text))
AddHandler Timer.Tick, AddressOf Timer_Tick
Timer.Interval = New TimeSpan(0, 0, 1)
If ButtonStart.Content = "START" Then
ProgressBar1.Maximum = StartTime
Timer.Start()
LabelPercent1.Content = (StartTime/100)
End If
End Sub
Sub ButtonStart_Copy_Click(sender As Object, e As RoutedEventArgs) Handles ButtonStart_Copy.Click
End Sub
End Class
我會試試看,我是新來編碼,你有什麼樣的例子? –
@ChrisScott問題是,我不知道如何編寫VB代碼,但我可以閱讀它們... – Jai
IsTimerRunning工作,謝謝你! –