Resources » Code Snippets » Winforms Controls

Progress bar sample in VB.net windows Application


Posted Date: 14-Aug-2008  Last Updated:   Category: Winforms Controls    
Author: Member Level: Gold    Points: 10



This code sample uses a Progress bar control in a windows Application. Add a new Progress bar control and add a new timer to a windows application form. Set the Progress bar's Step property to 20. Go the property of the timer and add set the Enable property of the timer to true.


In form load add the below code to initialize the progress bar Control
ProgressBar1.Minimum = 0
ProgressBar1.Maximum = 100
ProgressBar1.Value = 0
On double click of the timer event it will add the timer_tick event and add the progress bar code in timer event
ProgressBar1.Value += 2
If ProgressBar1.Value >= 100 Then
ProgressBar1.Value = 0
End If

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
ProgressBar1.Value += 2
If ProgressBar1.Value >= 100 Then
ProgressBar1.Value = 0
End If

End Sub


Run the application - this will fill the progress bar and it will again reset and the cycle .
If you want to fill the progress bar once. Add the below code in the timer event


If ProgressBar1.Value >= 100 Then
Timer1.Enable=False
End If


Did you like this resource? Share it with your friends and show your love!

Responses to "Progress bar sample in VB.net windows Application"
Author: srinivasa reddy tatikonda    10 Jan 2009Member Level: Silver   Points : 2
Hi
Create a New Project in VB.net. Drag a Progress bar control from tool box and place on form and now drag and drop four buttons on form having text l< << >> >l. this is simple interface for this purpose.

Now write code on form load even of the form



Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load



ProgressBar1.Minimum = 0

ProgressBar1.Maximum = 100

ProgressBar1.Value = 0



End Sub

Now write code on button click events.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click



If ProgressBar1.Value < 100 Then

ProgressBar1.Value += 5

End If



End Sub





Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click



If ProgressBar1.Value > 0 Then

ProgressBar1.Value -= 5


End If



End Sub





Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click



ProgressBar1.Value = 100



End Sub





Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click



ProgressBar1.Value = 0



End Sub



This is code for buttons now we will see how we can work with progress bar with mouse wheel scrolling. Select MouseWheel event from form1 events.Now write simple code in this event:



Private Sub Form1_MouseWheel(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseWheel



If e.Delta > -1 Then

If ProgressBar1.Value < 100 Then

ProgressBar1.Value += 5



End If

Else

If ProgressBar1.Value > 0 Then

ProgressBar1.Value -= 5



End If

End If



End Sub

Now in if condition you see that e.delta > -1 this is important for us when we scroll mouse one time control comes in this event and if we scroll wheel up side e.delta value will < 0 and if we scroll down side e.delta value > 0. Only remember these things in mind. Now see this condition ProgressBar1.Value < 100 we are handling the exception and also in ProgressBar1.Value > 0 because progressbar value should be in range of progressbar1.minimum and progressbar1.maximum.

This will Helpful to u

Best Regards
Srinivasa Reddy



Feedbacks      

Post Comment:




  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:   Sign In to fill automatically.
    Email: (Will not be published, but required to validate comment)



    Type the numbers and letters shown on the left.


    Submit Article     Return to Article Index

    Subscribe to Subscribers
    Active Members
    TodayLast 7 Daysmore...

    Awards & Gifts
    Talk to Webmaster Tony John
    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India