user1769878
user1769878

Reputation: 51

Adding a Progress Bar from a simple copy to the C Drive

I am using this code:

My.Computer.FileSystem.CopyFile(
            "Software\Service Packs\WindowsXP\SP2\WindowsXP-KB835935-SP2-ENU.exe",
            "C:\Service Pack\WindowsXP-KB835935-SP2-ENU.exe")

        Process.Start("C:\Service Pack\WindowsXP-KB835935-SP2-ENU.exe")

This simply copies Windows XP Service Pack from a pendrive to the C Drive located above.

I wish to add a Progress bar to the Form and need the code in order to do this.

Thank you,

Upvotes: 0

Views: 623

Answers (1)

Kashish Arora
Kashish Arora

Reputation: 908

Drag a ProgressBar and Timer to the form.

Add the following code under Timer1_Tick event:

Code And Example

Private Sub Timer1_Tick () Handles Timer1.Tick
      ProgressBar1.Increment (20)
      If ProgressBar1.Value = ProgressBar1.Maximum then
           Timer1.Stop
           'Add things here you want to do when progressbar reaches maximum.  
      End If
End Sub

Private Sub Form1_Load () Handles Mybase.Load
      Timer1.Stop
End Sub

Private Sub Button1_Click () Handles Button1.Click
      Timer1.Start
End Sub

Explanation

The value specified in the ProgressBar1.Increment means the percentage of increase. It will stop increasing when the value is maximum.

The Statement Timer1.Start must be added to the event from which you want to trigger the ProgressBar (Not necessary to write under the Form_Load event).

Hope it works perfectly.

Upvotes: 1

Related Questions