hi all
im creating a simple timer.it have NumericUpDown and Progress Bar.
i use NumericUpDown to set the timer in minutes.I also put Progress Bar to indicates the percentage of times completed.For example if i set the timer to 1 minutes so if it at 0.5 minutes the Progress Bar will show 50% completed.But the problem here is the Progress Bar is not working.

here is the coding

Public Class Form1
    Inherits System.Windows.Forms.Form

 Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick


        If ProgressBar1.Value < ProgressBar1.Maximum Then
            ProgressBar1.Value += 2
        Else
            ProgressBar1.Value = ProgressBar1.Minimum
        End If

        lblmsg.Text = "Percentage Complete : " & ProgressBar1.Value & "%"
        Timer1.Enabled = False

    End Sub


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim Minutes As Integer = NumericUpDown1.Value
        Timer1.Interval = Minutes * 60 * 1000
        Timer1.Enabled = True
        MsgBox("The timer has been set.", MsgBoxStyle.Information And MsgBoxStyle.OKOnly, "Timer Set")

    End Sub

    Private Sub NumericUpDown1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NumericUpDown1.ValueChanged

    End Sub

    Private Sub ProgressBar1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ProgressBar1.Click

    End Sub
End Class

any thought?

I would do this instead in the Timer_Tick event:

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick


        If ProgressBar1.Value >= ProgressBar1.Maximum Then
            ProgressBar1.Value = ProgressBar1.Minimum
            Timer1.Enabled = False
        Else
            ProgressBar1.Increment(2)    '' Notice the difference?
            If ProgressBar1.Value >= ProgressBar1.Maximum Then
                        ProgressBar1.Value = ProgressBar1.Maximum
                        Timer1.Enabled = False
            End If
            lblmsg.Text = "Percentage Complete : " & ProgressBar1.Value & "%"
        End If
    End Sub

Redundacy is sometimes a good thing.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.