progress bar..

lOnEr

Member
Joined
Jun 18, 2004
Messages
14
Programming Experience
Beginner
progress bar..[resolve]

hi..im very new in vb.net
how to use progress bar in my apps..

could someone guide me in this thing...

thanks in advance..
 
Last edited:

lOnEr

Member
Joined
Jun 18, 2004
Messages
14
Programming Experience
Beginner
Michaelk said:
I know how to run a progess bar based on a timer. But not sure about load times. Let me know if thats what your after.
halu thanks for the reply..
what i want is when i click the button it will run the progress bar.

tanx in advance..
 

Michaelk

Well-known member
Joined
Jun 3, 2004
Messages
58
Location
Australia
Programming Experience
3-5
Ok, use this to run a progess bar based on a timer.

- You will need a timer called "time"
- and a progess bar called "progressBar1"

On the button_click put this:
VB.NET:
[size=2]
[/size][size=2][color=#008000]' Connect the Tick event of the timer to its event handler.[/color][/size]
[size=2][color=#0000ff]AddHandler[/color][/size][size=2] time.Tick, [/size][size=2][color=#0000ff]AddressOf[/color][/size][size=2] IncreaseProgressBar[/size]
[size=2][color=#008000]' Start the timer.[/color][/size]
[size=2]time.Start()
[/size]
And put these 2 Private Subs in as well:
VB.NET:
[size=2]
[/size][size=2][color=#0000ff]Private[/color][/size][size=2] [/size][size=2][color=#0000ff]Sub[/color][/size][size=2] InitializeMyTimer()[/size]
[size=2][color=#008000]' Set the interval for the timer.[/color][/size]
[size=2]time.Interval = 100
[/size][size=2][color=#008000]' Connect the Tick event of the timer to its event handler.[/color][/size]
[size=2][color=#0000ff]AddHandler[/color][/size][size=2] time.Tick, [/size][size=2][color=#0000ff]AddressOf[/color][/size][size=2] IncreaseProgressBar[/size]
[size=2][color=#008000]' Start the timer.[/color][/size]
[size=2]time.Start()
[/size][size=2][color=#0000ff]End[/color][/size][size=2] [/size][size=2][color=#0000ff]Sub
[/color][/size]
and:

VB.NET:
[size=2]
[/size][size=2][color=#0000ff]Private[/color][/size][size=2] [/size][size=2][color=#0000ff]Sub[/color][/size][size=2] IncreaseProgressBar([/size][size=2][color=#0000ff]ByVal[/color][/size][size=2] sender [/size][size=2][color=#0000ff]As[/color][/size][size=2] [/size][size=2][color=#0000ff]Object[/color][/size][size=2], [/size][size=2][color=#0000ff]ByVal[/color][/size][size=2] e [/size][size=2][color=#0000ff]As[/color][/size][size=2] EventArgs)[/size]
[size=2][color=#008000]' Increment the value of the ProgressBar a value of one each time.[/color][/size]
[size=2]ProgressBar1.Increment(1)
[/size][size=2][color=#008000]' Display the textual value of the ProgressBar in the StatusBar control's first panel.[/color][/size]
[size=2]statusBarPanel1.Text = ProgressBar1.Value.ToString() + "% Completed"
[/size][size=2][color=#008000]' Determine if we have completed by comparing the value of the Value property to the Maximum value.[/color][/size]
[size=2][color=#0000ff]If[/color][/size][size=2] ProgressBar1.Value = ProgressBar1.Maximum [/size][size=2][color=#0000ff]Then[/color][/size]
[size=2][color=#008000]' Stop the timer.[/color][/size]
[size=2]time.Stop()
[/size][size=2][color=#0000ff][size=2][color=#008000]'Put what you want to run after the progess bar is finished here.

[/color][/size][/color][/size][size=2][color=#0000ff]End[/color][/size][size=2] [/size][size=2][color=#0000ff]If[/color][/size]
[size=2][color=#0000ff]End[/color][/size][size=2] [/size][size=2][color=#0000ff]Sub[/color][/size]
Hope thats what your after
Good luck,
 

lOnEr

Member
Joined
Jun 18, 2004
Messages
14
Programming Experience
Beginner
tanx for your effort...
but im sorry to tell you this the code did not work..

VB.NET:
  Private Sub initializetimer()
  		Timer1.Interval = 100
  		AddHandler Timer1.Tick, AddressOf increaseprogress
  		Timer1.Start()
  	End Sub
  	Private Sub increaseprogress(ByVal sender As Object, ByVal e As EventArgs)
  		ProgressBar1.Increment(1)
  		StatusBarpanel1.Text = ProgressBar1.Value.ToString() + "%completed"
  		If ProgressBar1.Minimum = ProgressBar1.Maximum Then
  			Timer1.Stop()
  		End If
  	End Sub
  
 	Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  		AddHandler Timer1.Tick, AddressOf increaseprogress
  	End Sub
thanks..
 
Last edited:

lOnEr

Member
Joined
Jun 18, 2004
Messages
14
Programming Experience
Beginner
what do you mean i will remove it??

ok i already remove it but nothing happens..
 

Paszt

Staff member
Joined
Jun 3, 2004
Messages
1,500
Location
Raleigh, NC - USA
Programming Experience
Beginner
If you could elaborate more on what you're trying to show the progress of, I'll be glad to attempt to help.

Generally the progress bar is used to show the progress of something (obvious, I know). You would calculate the percent complete of whatever function you're doing and set the progressBar.Value property accordingly.

In your code above you have the line 'If ProgressBar1.Minimum = ProgressBar1.Maximum Then'. The Minimum value will not usually ever equal the Maximum Value (the progressBar would serve no purpose if they were equal, though it is possible). The timer should never stop.
 

mzim

Well-known member
Joined
Jun 3, 2004
Messages
187
Location
Other side of the rock
Programming Experience
1-3
Originally deleted by the author
 

lOnEr

Member
Joined
Jun 18, 2004
Messages
14
Programming Experience
Beginner
Paszt said:
If you could elaborate more on what you're trying to show the progress of, I'll be glad to attempt to help.

Generally the progress bar is used to show the progress of something (obvious, I know). You would calculate the percent complete of whatever function you're doing and set the progressBar.Value property accordingly.

In your code above you have the line 'If ProgressBar1.Minimum = ProgressBar1.Maximum Then'. The Minimum value will not usually ever equal the Maximum Value (the progressBar would serve no purpose if they were equal, though it is possible). The timer should never stop.
halu Paszt thanks in advance...
heres what i want..
i want to run a progressbar as well as status bar in app's by clicking a button..
im very new in this thing.
tanx and more power.
 

mzim

Well-known member
Joined
Jun 3, 2004
Messages
187
Location
Other side of the rock
Programming Experience
1-3
lOnEr said:
halu Paszt thanks in advance...
heres what i want..
i want to run a progressbar as well as status bar in app's by clicking a button..
im very new in this thing.
tanx and more power.
VB.NET:
 Public Sub progress()
 		StatusBar1.Text = "connecting to the database"
 		If ProgressBar1.Value = ProgressBar1.Maximum Then
 			ProgressBar1.Value = ProgressBar1.Maximum
 		End If
 		Dim i As Integer
 		For i = ProgressBar1.Minimum To ProgressBar1.Maximum
 			ProgressBar1.PerformStep()
 		Next
 	End Sub
 
 	Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
 		progress()
 	End Sub
set the progressbar1.maximum to 10000 and progressbar1.minimum to 1

hope it helps..
happy coding:cool:
 

lOnEr

Member
Joined
Jun 18, 2004
Messages
14
Programming Experience
Beginner
mzim said:
VB.NET:
 Public Sub progress()
 		StatusBar1.Text = "connecting to the database"
 		If ProgressBar1.Value = ProgressBar1.Maximum Then
 			ProgressBar1.Value = ProgressBar1.Maximum
 		End If
 		Dim i As Integer
 		For i = ProgressBar1.Minimum To ProgressBar1.Maximum
 			ProgressBar1.PerformStep()
 		Next
 	End Sub
 
 	Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
 		progress()
 	End Sub
set the progressbar1.maximum to 10000 and progressbar1.minimum to 1

hope it helps..
happy coding:cool:
hi..mzim thanks..it really works..


more power...
 
Top Bottom