Monday, February 24, 2014

VB.Net Progressbar

______________________________________________________

Progressbar control is used to show the status or progress of a specific task the application is currently doing. This control helps the user to determine whether the program is still responsive or not. Progressbar shows the percentage of a specific task and can estimate when the task will be ended.

This tutorial will show you how to utilize a progressbar in your window form application.

1. Create a new project on vb.net and name it "Progressbar".

2. On your window form, drag and drop these 3 objects from the toolbox:
                                                       - Progressbar
                                                       - Button
                                                       - Label
                                                       - Timer

3. Try to patter your control like what I did below:

4. Click on the label>properties>change the text attribute to "0%"

5. Double click you button to create your code.

6. In button button click event, you need to enable the timer because it is currently disabled. Follow this code:
                               Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
                                              Timer1.Enabled = True
                               End Sub

7. After enabling the timer, double click the timer object on your design and put the command that will create the progressbar event. Follow this code inside the timer event.
                    Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick       

                               If Not ProgressBar1.Value = 100 Then
                                              ProgressBar1.Value += 1
                                              Label1.Text = ProgressBar1.Value & " %"
                               Else
                                              Timer1.Enabled = False
                                              MsgBox("Hellow World")
                               End If            
                      End Sub

As you can see, we used the IF ELSE statement for the reason that we need to stop the timer after we reached 100 % of the progress. We also put a messagebox "Hello Word" after we had reached the progress. Then you can see that our label has its value. The label will show the percentage of the progress by simply giving the value of the progressbar to the  "Text" attribute of the label.


9. You done, run the program by hitting F5 and start clicking the button.




______________________________________________________

No comments:

Post a Comment