[VB.net]カウントダウンタイマー



Countdown Timer



VB.netでカウントダウンプログラムを書いてみてください。簡単な結果を上に示し、コードを以下に示します。



Public Class Form1 Private Sub StBt_Click(sender As Object, e As EventArgs) Handles StBt.Click PrBar.Value = 0 TB2.Text = '' Timer1.Start() End Sub Private Sub PaBt_Click(sender As Object, e As EventArgs) Handles PaBt.Click Timer1.Stop() End Sub Private Sub ClBt_Click(sender As Object, e As EventArgs) Handles ClBt.Click Timer1.Stop() PrBar.Value = 0 TB2.Text = '' End Sub Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick Dim i As Integer Dim ratio As Single Timer1.Interval = 1000 'The timer unit is 1ms, and 1000 refers to set timer1 in seconds. PrBar.Increment(PrBar.Maximum / TB1.Text) 'progress bar is displayed in proportion to the input TB1 value Ratio = PrBar.Value / PrBar.Maximum 'Show progress ratio in log progress TB2.AppendText(DateTime.Now + ' progress ' + ratio.ToString('p2') + Environment.NewLine) 'Logging If PrBar.Value = PrBar.Maximum Then 'If the progress bar is completed, the Timer stops Timer1.Stop() MsgBox ('reciprocal completion') End If End Sub Private Sub TB1_TextChanged(sender As Object, e As EventArgs) Handles TB1.TextChanged Timer1.Stop() PrBar.Value = 0 TB2.Text = '' End Sub End Class