What this done is simple.
When I click on a Button the progress bar will show for 5 seconds and then some other work can be done. Well, here it is.
'Simple Timer demo by Sarthak Ganguly
'Released under GPLv3 Share Alike License.
Public Class MainFrm
'Say 2 seconds is the default timeout
'You can change it from here or make it a
'property with Get and Set statements
'you can increase it to 3,4,5... seconds
Dim timeLimit As Integer = 50 * 100 '(milliseconds)
Dim temp As Integer = 0
Private Sub clickBUT_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles clickBUT.Click
'Start the timer
aTmr.Enabled = True
End Sub
Private Sub aTmr_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles aTmr.Tick
'The timer ticks :) with Step 100ms
progBar.Value += OneStep()
'Stop the Timer
temp += 100
If temp = timeLimit Then
aTmr.Enabled = False
temp = 0
'Add code if you want anything to happen after progressbar
'reaches maximum value
End If
End Sub
'This is the most important function as it will return the
'relative unit size of the progress bar
Private Function OneStep() As Integer
'One unit returned and converted to nearest Integer
Return CInt(progBar.Maximum / (timeLimit / 100))
End Function
End Class
Comments
Post a Comment
No spam please :)