My progress bar is disappearing - vb.net

My progressbar is disappearing as soon as I start running any code. Why's that?
That's really strange.
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
StartThinking()
For Each z In ListBox1.Items
Dim u = FindIPAddress(z)
ListBox2.Items.Add(If(IsNothing(u), "Not found!", u))
Next
StopThinking()
End Sub
Sub StartThinking()
Cursor = Cursors.WaitCursor
ProgressBar1.Minimum = 0
ProgressBar1.Style = ProgressBarStyle.Marquee
End Sub
Sub StopThinking()
ProgressBar1.Minimum = ProgressBar1.Maximum
ProgressBar1.Style = ProgressBarStyle.Blocks
Cursor = Cursors.Arrow
End Sub

Related

Switch textboxes to enter automatically after time

So I am making this sort of clock thing and I find it hard to discover a way to switch from textbox to another textbox every second. I've tried timers and dispatchtimer but I didn't succeed so I am looking for some expert tips.
The code below works.
Here's my vb.net script:
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
AddHandler TextBox1.Enter, AddressOf TextBox1_Enter
AddHandler TextBox2.Enter, AddressOf TextBox2_Enter
AddHandler TextBox3.Enter, AddressOf TextBox3_Enter
AddHandler TextBox4.Enter, AddressOf TextBox4_Enter
AddHandler TextBox5.Enter, AddressOf TextBox5_Enter
AddHandler TextBox6.Enter, AddressOf TextBox6_Enter
AddHandler TextBox7.Enter, AddressOf TextBox7_Enter
AddHandler TextBox8.Enter, AddressOf TextBox8_Enter
AddHandler TextBox9.Enter, AddressOf TextBox9_Enter
AddHandler TextBox10.Enter, AddressOf TextBox10_Enter
AddHandler TextBox11.Enter, AddressOf TextBox11_Enter
AddHandler TextBox12.Enter, AddressOf TextBox12_Enter
End Sub
Private Sub TextBox1_Enter(sender As Object, e As EventArgs)
BackColor = Color.Red
End Sub
Private Sub TextBox2_Enter(sender As Object, e As EventArgs)
BackColor = Color.Blue
End Sub
Private Sub TextBox3_Enter(sender As Object, e As EventArgs)
BackColor = Color.Yellow
End Sub
Private Sub TextBox4_Enter(sender As Object, e As EventArgs)
BackColor = Color.Green
End Sub
Private Sub TextBox5_Enter(sender As Object, e As EventArgs)
BackColor = Color.Pink
End Sub
Private Sub TextBox6_Enter(sender As Object, e As EventArgs)
BackColor = Color.Teal
End Sub
Private Sub TextBox7_Enter(sender As Object, e As EventArgs)
BackColor = Color.SteelBlue
End Sub
Private Sub TextBox8_Enter(sender As Object, e As EventArgs)
BackColor = Color.LightGray
End Sub
Private Sub TextBox9_Enter(sender As Object, e As EventArgs)
BackColor = Color.Gold
End Sub
Private Sub TextBox10_Enter(sender As Object, e As EventArgs)
BackColor = Color.BlueViolet
End Sub
Private Sub TextBox11_Enter(sender As Object, e As EventArgs)
BackColor = Color.Orange
End Sub
Private Sub TextBox12_Enter(sender As Object, e As EventArgs)
BackColor = Color.Brown
End Sub
End Class
I am also posting a design of a clock for better imagination of the idea.
Well, i'm no professional (which will be evident by the long way i've come up with a solution, i'm sure someone who does it for a living could get it done much more eloquently) but here's what i came up with as it seemed like a fun task.
I've got it stating a timer on launch, then when the button is clicked a new thread is started in the background, that new thread increments a counter every second, and timer1_tick is constantly checking what the counter value is and adjusting the form and textboxes accordingly, it's changing the colour, putting the number in and making it the focused item.
You'll need the following items on Form1:
Textboxes 1 to 12 (in the pattern you provided with 12 being the top one)
A button (Button1)
Drag a timer (Timer1) onto Form1
Then replace the code on Form1 with the below
Imports System.Threading
Public Class Form1
Dim WorkerThread As New Thread(AddressOf DoWork)
Public StartStop As Boolean
Dim Counter As Integer
Private Sub DoWork()
StartStop = False
Do Until StartStop = True
Counter = 0
Do Until Counter = 13
Counter = Counter + 1
Application.DoEvents()
If Counter < 13 Then Threading.Thread.Sleep(1000)
Loop
Loop
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
WorkerThread.Start()
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
Timer1.Start()
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
ClearAllTBs()
If Counter = 1 Then
TextBox1.BackColor = Color.Bisque
TextBox1.Text = "1"
TextBox1.Focus()
End If
If Counter = 2 Then
TextBox2.BackColor = Color.Beige
TextBox2.Text = "2"
TextBox2.Focus()
End If
If Counter = 3 Then
TextBox3.BackColor = Color.CornflowerBlue
TextBox3.Text = "3"
TextBox3.Focus()
End If
If Counter = 4 Then
TextBox4.BackColor = Color.Crimson
TextBox4.Text = "4"
TextBox4.Focus()
End If
If Counter = 5 Then
TextBox5.BackColor = Color.DarkCyan
TextBox5.Text = "5"
TextBox5.Focus()
End If
If Counter = 6 Then
TextBox6.BackColor = Color.DarkMagenta
TextBox6.Text = "6"
TextBox6.Focus()
End If
If Counter = 7 Then
TextBox7.BackColor = Color.Gold
TextBox7.Text = "7"
TextBox7.Focus()
End If
If Counter = 8 Then
TextBox8.BackColor = Color.Fuchsia
TextBox8.Text = "8"
TextBox8.Focus()
End If
If Counter = 9 Then
TextBox9.BackColor = Color.DarkViolet
TextBox9.Text = "9"
TextBox9.Focus()
End If
If Counter = 10 Then
TextBox10.BackColor = Color.MediumSeaGreen
TextBox10.Text = "10"
TextBox10.Focus()
End If
If Counter = 11 Then
TextBox11.BackColor = Color.Navy
TextBox11.Text = "11"
TextBox11.Focus()
End If
If Counter = 12 Then
TextBox12.BackColor = Color.BlueViolet
TextBox12.Text = "12"
TextBox12.Focus()
End If
Application.DoEvents()
End Sub
Private Sub Form1_Closed(sender As Object, e As EventArgs) Handles Me.Closed
StartStop = True
WorkerThread.Abort()
End Sub
Private Sub ClearAllTBs()
TextBox1.BackColor = Color.White
TextBox2.BackColor = Color.White
TextBox3.BackColor = Color.White
TextBox4.BackColor = Color.White
TextBox5.BackColor = Color.White
TextBox6.BackColor = Color.White
TextBox7.BackColor = Color.White
TextBox8.BackColor = Color.White
TextBox9.BackColor = Color.White
TextBox10.BackColor = Color.White
TextBox11.BackColor = Color.White
TextBox12.BackColor = Color.White
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
TextBox5.Text = ""
TextBox6.Text = ""
TextBox7.Text = ""
TextBox8.Text = ""
TextBox9.Text = ""
TextBox10.Text = ""
TextBox11.Text = ""
TextBox12.Text = ""
End Sub
End Class

Vb.net navigation

I'm, trying to navigate through my records but when I press the buttons, nothing happens. I'm using Jet 4.0 and an Access DB.
I'm not sure what I'm doing wrong but if anyone can help me in the right direction, it would be appreciated.
Code:
Private Sub showData(ByVal CurrentRow)
CurrentRow = 0
Dad.Fill(dst, "patrolDB")
TextBox27.Text = dst.Tables("patrolDB").Rows(CurrentRow)("ID").ToString.ToUpper
DateTimePicker1.Text = dst.Tables("patrolDB").Rows(CurrentRow)("patroldate").ToString.ToUpper
TextBox2.Text = dst.Tables("patrolDB").Rows(CurrentRow)("patroltime").ToString.ToUpper
ComboBox1.Text = dst.Tables("patrolDB").Rows(CurrentRow)("patroltype").ToString.ToUpper
ComboBox2.Text = dst.Tables("patrolDB").Rows(CurrentRow)("patrolsite").ToString.ToUpper
ComboBox4.Text = dst.Tables("patrolDB").Rows(CurrentRow)("patrolloc").ToString.ToUpper
ComboBox3.Text = dst.Tables("patrolDB").Rows(CurrentRow)("patrolofficer").ToString.ToUpper
RichTextBox1.Text = dst.Tables("patrolDB").Rows(CurrentRow)("patrolnotes").ToString.ToUpper
Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
If CurrentRow <> dst.Tables("patrolDB").Rows.Count - 1 Then
CurrentRow += 1
showData(CurrentRow)
End If
MsgBox("You've reached the last record.")
End Sub
Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
index = 0
showData(CurrentRow)
End Sub
Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click
If CurrentRow <> 0 Then
CurrentRow -= 1
showData(CurrentRow)
End If
MsgBox("You've reached the first record.")
End Sub
Private Sub Button8_Click(sender As Object, e As EventArgs) Handles Button8.Click
CurrentRow = dst.Tables("patrolDB").Rows.Count - 1
showData(CurrentRow)
End Sub
Dim table As DataTable
Private Sub LoadData()
CurrentRow = 0
Dad.Fill(dst, "patrolDB")
table = dst.Tables("patrolDB") 'for the comfort
ShowCurrentRow()
End Sub
Private Sub ShowCurrentRow()
TextBox27.Text = table.Rows(CurrentRow)("ID").ToString.ToUpper
DateTimePicker1.Text = table.Rows(CurrentRow)("patroldate").ToString.ToUpper
TextBox2.Text = table.Rows(CurrentRow)("patroltime").ToString.ToUpper
ComboBox1.Text = table.Rows(CurrentRow)("patroltype").ToString.ToUpper
ComboBox2.Text = table.Rows(CurrentRow)("patrolsite").ToString.ToUpper
ComboBox4.Text = table.Rows(CurrentRow)("patrolloc").ToString.ToUpper
ComboBox3.Text = table.Rows(CurrentRow)("patrolofficer").ToString.ToUpper
RichTextBox1.Text = table.Rows(CurrentRow)("patrolnotes").ToString.ToUpper
End Sub
'go to next
Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
If CurrentRow <> table.Rows.Count - 1 Then
CurrentRow += 1
ShowCurrentRow()
Else MsgBox("You've reached the last record.")
End If
End Sub
'go to prev
Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click
If CurrentRow <> 0 Then
CurrentRow -= 1
ShowCurrentRow()
Else MsgBox("You've reached the first record.")
End If
End Sub
'go to start
Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
index = 0
ShowCurrentRow()
End Sub
'go to last
Private Sub Button8_Click(sender As Object, e As EventArgs) Handles Button8.Click
CurrentRow = table.Rows.Count - 1
ShowCurrentRow()
End Sub

BackgroundWorker not updating GUI at other Form

As stated I have a BackgroundWorker that runs a sub function DoHeavyWork().
Private Sub BackgroundWorker1_DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
If BackgroundWorker1.CancellationPending = True Then
e.Cancel = True
Else
'DO HEAVY WORK
DoHeavyWork()
End If
End Sub
Private Sub BackgroundWorker1_ProgressChanged(sender As Object, e As System.ComponentModel.ProgressChangedEventArgs) Handles BackgroundWorker1.ProgressChanged
ProgressBar1.Value = e.ProgressPercentage
Label8.Text = e.ProgressPercentage.ToString() + " %"
End Sub
Private Sub BackgroundWorker1_RunWorkerCompleted(sender As Object, e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles BackgroundWorker1.RunWorkerCompleted
If e.Cancelled = True Then
ProgressBar1.Value = 0
Label8.Text = ""
ElseIf e.Error IsNot Nothing Then
MessageBox.Show(e.Error.Message)
Else
MessageBox.Show("Completed!")
End If
End Sub
Inside this sub function DoHeavyWork(), there are codes to update another form's GUI.
Private Sub DoHeavyWork()
For i As Integer = 1 To fresult_counter
Dim fresult As New Button
fresult.Name = "fresult_" & i
fresult.Text = result(index_acc(i - 1)).ToString
fresult.TextAlign = ContentAlignment.MiddleLeft
fresult.Width = 265
fresult.AutoSize = True
fresult.BackColor = Color.White
With fresult.FlatAppearance
.BorderColor = Color.White
.BorderSize = 2
.MouseDownBackColor = Color.DeepSkyBlue
.MouseOverBackColor = Color.DeepSkyBlue
End With
fresult.Anchor = AnchorStyles.Left
fresult.FlatStyle = FlatStyle.Flat
fresult.UseVisualStyleBackColor = False
fresult.Location = New Point(0, 22 * (i - 1))
Form1.TabControl2.TabPages(1).Controls.Add(fresult)
BackgroundWorker1.ReportProgress(i)
Next
End Sub
The problem is it did not update the GUI but the progress bar is working. I've tried getting the set of code out of the BackgroundWorker and it works fine. Is there something I did not set to enable BackgroundWorker to update the GUI?
As mentioned by jmcilhinney, the solution for my answer is very simple.
Just let the BackgroundWorker update the progress bar at the background. And when it finished doing it's work, the progress bar will be at 100 which means it is completed.
Once it is completed, simply add the update GUI codings (in my case: 'Form1.TabControl2.TabPages(1).Controls.Add(fresult)') at the sub function when BackgroundWorker has completed:
Private Sub BackgroundWorker1_RunWorkerCompleted(sender As Object, e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles BackgroundWorker1.RunWorkerCompleted
If e.Cancelled = True Then
ProgressBar1.Value = 0
Label8.Text = ""
ElseIf e.Error IsNot Nothing Then
MessageBox.Show(e.Error.Message)
Else
MessageBox.Show("Completed!")
Form1.TabControl2.TabPages(1).Controls.Add(fresult)
End If
End Sub

Form doesn't update while running button click event

I'm trying to update a progress bar at the end of each method in Visual Basic, the problem is that label1.Text does not update itself at the start at each method but will update.
Public Class Form2
Private Const METHOD_COUNT = 4
Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
ProgressBar1.Maximum = METHOD_COUNT
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Method_One()
Method_Two()
Method_Three()
Method_Four()
End Sub
Private Sub Method_One()
Label1.Text = "Loading Method One"
ProgressBar1.Value += 1
'Threading.Thread.Sleep(1000)
End Sub
Private Sub Method_Two()
Label1.Text = "Loading Method Two"
ProgressBar1.Value += 1
'Threading.Thread.Sleep(1000)
End Sub
Private Sub Method_Three()
Label1.Text = "Loading Method Three"
ProgressBar1.Value += 1
'Threading.Thread.Sleep(1000)
End Sub
Private Sub Method_Four()
Label1.Text = "Loading Method Four"
ProgressBar1.Value += 1
'Threading.Thread.Sleep(1000)
End Sub
End Class
So basically when you run this, it will execute and update the progress bar nicely, but the label does not update. I think it might have something to do with multithreading and the fact the form does not get a constant update.
The "quick fix" is to add Application.DoEvents() before each call to Sleep():
Public Class Form2
Private Const METHOD_COUNT = 4
Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
ProgressBar1.Maximum = METHOD_COUNT
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Method_One()
Method_Two()
Method_Three()
Method_Four()
End Sub
Private Sub Method_One()
Label1.Text = "Loading Method One"
ProgressBar1.Value += 1
Application.DoEvents()
Threading.Thread.Sleep(1000)
End Sub
Private Sub Method_Two()
Label1.Text = "Loading Method Two"
ProgressBar1.Value += 1
Application.DoEvents()
Threading.Thread.Sleep(1000)
End Sub
Private Sub Method_Three()
Label1.Text = "Loading Method Three"
ProgressBar1.Value += 1
Application.DoEvents()
Threading.Thread.Sleep(1000)
End Sub
Private Sub Method_Four()
Label1.Text = "Loading Method Four"
ProgressBar1.Value += 1
Application.DoEvents()
Threading.Thread.Sleep(1000)
End Sub
End Class
The "correct fix" is that your "work" should not be done in the main UI thread, which is what you're doing be calling those methods from the button click handler. Instead, you need to move the work to a background thread so that the UI can update itself. Take a look at using the BackgroundWorker() control. You call its ReportProgress() method which fires the ProgressChanged() event. From that event it's safe to update the UI. When the work in the background thread is complete you'll get a RunWorkerCompleted() event. Note that you have to set the WorkerReportsProgress() property to True if you want to use the progress events:
Public Class Form2
Private Const METHOD_COUNT = 4
Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
ProgressBar1.Maximum = METHOD_COUNT
BackgroundWorker1.WorkerReportsProgress = True
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If Not BackgroundWorker1.IsBusy Then
Button1.Enabled = False
BackgroundWorker1.RunWorkerAsync()
End If
End Sub
Private Sub BackgroundWorker1_DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
Method_One()
Method_Two()
Method_Three()
Method_Four()
End Sub
Private Sub Method_One()
BackgroundWorker1.ReportProgress(1, "Loading Method One")
Threading.Thread.Sleep(1000)
End Sub
Private Sub Method_Two()
BackgroundWorker1.ReportProgress(2, "Loading Method Two")
Threading.Thread.Sleep(1000)
End Sub
Private Sub Method_Three()
BackgroundWorker1.ReportProgress(3, "Loading Method Three")
Threading.Thread.Sleep(1000)
End Sub
Private Sub Method_Four()
BackgroundWorker1.ReportProgress(4, "Loading Method Four")
Threading.Thread.Sleep(1000)
End Sub
Private Sub BackgroundWorker1_ProgressChanged(sender As Object, e As System.ComponentModel.ProgressChangedEventArgs) Handles BackgroundWorker1.ProgressChanged
Label1.Text = e.UserState
ProgressBar1.Value = e.ProgressPercentage
End Sub
Private Sub BackgroundWorker1_RunWorkerCompleted(sender As Object, e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles BackgroundWorker1.RunWorkerCompleted
Button1.Enabled = True
MessageBox.Show("Done!")
End Sub
End Class
If you think the value of the label is being changed, but the screen is not being updated have you tried the refresh method?
For example:
Private Sub Method_Three()
Label1.Text = "Loading Method Three"
Label1.Refresh
ProgressBar1.Value += 1
'Threading.Thread.Sleep(1000)
End Sub
I am sure someone else can explain why this is but i have always had to use the following to get Labels to update when they wouldn't otherwise:
Private Sub Method_Three()
With Label1
.Text = "Loading Method Three"
.Refresh
End With
ProgressBar1.Value += 1
'Threading.Thread.Sleep(1000)
End Sub

VB.net stopping a backgroundworker

I want to create a button that could stop my background worker and end all the process it is working on.
Here is my sample backgroundworker code:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Try
If BackgroundWorker1.IsBusy <> True Then
BackgroundWorker1.RunWorkerAsync()
End If
Catch ex As Exception
End Try
End Sub
Private Sub BackgroundWorker1_DoWork(sender As System.Object, e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
Dim counter As Integer = 1
Do
'updated code with stop function----------------
BackgroundWorker1.WorkerSupportsCancellation = True
If BackgroundWorker1.CancellationPending Then
e.Cancel = True
ProgressBar1.Value = 0
Exit Do
End If
'updated code with stop function----------------
ListBox1.Items.Add(counter)
ProgressBar1.Value = ((counter - 1) / limit) * 100
counter = counter + 1
Loop While(counter <= 999999999999999999)
End Sub
Private Sub BackgroundWorker1_ProgressChanged(sender As System.Object, e As System.ComponentModel.ProgressChangedEventArgs) Handles BackgroundWorker1.ProgressChanged
Try
Catch ex As Exception
End Try
End Sub
Private Sub BackgroundWorker1_Completed(sender As System.Object, e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles BackgroundWorker1.RunWorkerCompleted
Try
Catch ex As Exception
End Try
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
System.Windows.Forms.Control.CheckForIllegalCrossThreadCalls = False
End Sub
'updated code with stop function----------------
Private Sub StopButton_Click(sender As Object, e As EventArgs) Handles StopButton.Click
If BackgroundWorker1.IsBusy Then
If BackgroundWorker1.WorkerSupportsCancellation Then
BackgroundWorker1.CancelAsync()
End If
End If
End Sub
'updated code with stop function----------------
I want to reset the loop and return the Progress Bar to 0% when i stop the backgroundworker.
Is this possible?
The code above has been updated and it is now working fine.
I have added this code inside my do loop:
BackgroundWorker1.WorkerSupportsCancellation = True
If BackgroundWorker1.CancellationPending Then
e.Cancel = True
ProgressBar1.Value = 0
Exit Do
End If
I created a button that stops the worker:
Private Sub StopButton_Click(sender As Object, e As EventArgs) Handles StopButton.Click
If BackgroundWorker1.IsBusy Then
If BackgroundWorker1.WorkerSupportsCancellation Then
BackgroundWorker1.CancelAsync()
End If
End If
End Sub
The Backgroundworker class has the method CancelAsync() which you need to call to cancel the execution of the bgw.
You need to set the Backgroundworker.WorkerSupportsCancellation property to true and inside the while loop you need to check the CancellationPending property wether the value is true which indicates a call to the CancelAsync() method.
If CancellationPending evaluates to true, you would ( which you should have done already ) call one of the overloaded ReportProgress() (Docu) methods to set your ProgressBar value to the desired value.
EDIT: You should set the Cancel property of the DoWorkEventArgs to true so you can check the Cancelled property of the RunWorkerCompletedEventArgs inside the RunworkerCompletedevent.
You also shouldn not access any controls which lives in the UI thread. You better use the ProgressChanged(Docu) event.
See: BackgroundWorker Docu
Public Class Form1
Private iVal As Integer = 0
Private Sub bgw_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles bgw.DoWork
For iVal = iVal To 100 Step 1
bgw.ReportProgress(iVal)
Threading.Thread.Sleep(99)
If (bgw.CancellationPending = True) Then
e.Cancel = True
Exit For
End If
Next
End Sub
Private Sub bgw_ProgressChanged(ByVal sender As Object, ByVal e As System.ComponentModel.ProgressChangedEventArgs) Handles bgw.ProgressChanged
pbar.Value = e.ProgressPercentage
lblProgrss.Text = e.ProgressPercentage.ToString() & "%"
End Sub
Private Sub bgw_RunWorkerCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles bgw.RunWorkerCompleted
If (e.Cancelled = True) Then
pic.Visible = False
pbar.Value = iVal
lblProgrss.Text = iVal & "%"
btnstart.Text = "Start"
btnstart.BackColor = Color.Green
Else
pic.Visible = False
btnstart.Text = "Start"
btnstart.BackColor = Color.Green
iVal = 0
End If
End Sub
Private Sub btnstart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnstart.Click
If (btnstart.Text = "Start") Then
btnstart.Text = "Stop"
btnstart.BackColor = Color.Red
pic.Visible = True
bgw.RunWorkerAsync()
Else
If (bgw.IsBusy = True) Then
btnstart.Text = "Start"
btnstart.BackColor = Color.Green
bgw.CancelAsync()
End If
End If
End Sub
End Class