Rodney
Joined: 09 May 2008 Posts: 1
|
Posted: Fri May 09, 2008 11:09 am Post subject: Visual Basic Express - Help Needed |
|
|
Hi All
I am trying to create a program that eventually will backup data, my biggest challenge is that the progress bar runs when "previewing".
I would like to add a button "start" and connect the progress bar to execute when "start" is clicked.
I also would like the cancell button to close the entire program... sigh*
Any input will be appreciated !!
Public Class Form1
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.BackgroundWorker1.RunWorkerAsync()
ProgressBar1.Style = ProgressBarStyle.Continuous = 10000
ProgressBar1.Dock = DockStyle.Bottom
ProgressBar1.Visible = True
ProgressBar1.Minimum = 1
ProgressBar1.Maximum = 100
BackgroundWorker1.WorkerReportsProgress = True
BackgroundWorker1.WorkerSupportsCancellation = True
End Sub
Private Sub BackgroundWorker1_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
Dim i As Integer = 0
While (Not Me.BackgroundWorker1.CancellationPending) And i <= 99
i = i + 1
System.Threading.Thread.Sleep(200)
Me.BackgroundWorker1.ReportProgress(i) ' file processing here
End While
If (Me.BackgroundWorker1.CancellationPending) Then
e.Cancel = True
Else
End If
e.Result = "BACKUP COMPLETED"
End Sub
Private Sub BackgroundWorker1_ProgressChanged(ByVal sender As Object, ByVal e As System.ComponentModel.ProgressChangedEventArgs) Handles BackgroundWorker1.ProgressChanged
ProgressBar1.Visible = True
ProgressBar1.Value = e.ProgressPercentage
End Sub
Private Sub BackgroundWorker1_RunWorkerCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles BackgroundWorker1.RunWorkerCompleted
ProgressBar1.Visible = False
If (e.Error IsNot Nothing) Then
MessageBox.Show(e.Error.Message)
ElseIf e.Cancelled Then
MessageBox.Show("Canceled")
Else
End If
MessageBox.Show(e.Result.ToString)
If (e.Cancelled = True) Then
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.BackgroundWorker1.CancelAsync()
End Sub |
|