|
-
Mar 26th, 2008, 03:22 AM
#1
Thread Starter
Lively Member
[2008] Progress Bar
Can someone post some code on how the progress bar will work when the login screen is loading up ?
-
Mar 26th, 2008, 03:33 AM
#2
Re: [2008] Progress Bar
All ProgressBars work the same way. Either you call the PerformStep method or you set the Value property explicitly. The ProgressBar has no specific connection to any task. It's completely up to you to perfrom all the mathematics required to determine what the actual progress is, then update the control to display the appropriate value to the user.
-
Mar 26th, 2008, 05:02 AM
#3
Thread Starter
Lively Member
Re: [2008] Progress Bar
I dont know how to do that
-
Mar 26th, 2008, 05:09 AM
#4
Hyperactive Member
Re: [2008] Progress Bar
Here is some code so that when your form has loaded your progress bar will be filled gradually, just put this where you want.
Code:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ProgressBar1.PerformStep()
System.Threading.Thread.Sleep(100)
ProgressBar1.PerformStep()
System.Threading.Thread.Sleep(100)
ProgressBar1.PerformStep()
System.Threading.Thread.Sleep(100)
ProgressBar1.PerformStep()
System.Threading.Thread.Sleep(100)
ProgressBar1.PerformStep()
System.Threading.Thread.Sleep(100)
ProgressBar1.PerformStep()
System.Threading.Thread.Sleep(100)
ProgressBar1.PerformStep()
System.Threading.Thread.Sleep(100)
ProgressBar1.PerformStep()
System.Threading.Thread.Sleep(100)
ProgressBar1.PerformStep()
System.Threading.Thread.Sleep(100)
ProgressBar1.PerformStep()
End Sub
-
Mar 26th, 2008, 05:18 AM
#5
Re: [2008] Progress Bar
Why would anyone want to sleep the UI thread? Besides, since the Load event is raised before the form shows, you're not going to see the progressbar do anything, you will just delay the form showing by ~1 second from putting the UI thread to sleep.
-
Mar 26th, 2008, 05:38 AM
#6
Thread Starter
Lively Member
Re: [2008] Progress Bar
It doesnt work, on running the program, the progress bar is already filled up. And it just stays that way till the next form shows up.
-
Mar 26th, 2008, 05:44 AM
#7
Re: [2008] Progress Bar
You'd need to have something measureable in your code in order to have use of a ProgressBar. Dont just smack one on to your form and "fake" it like cameron2 showed you, its silly and serves no purpose.
Are you doing something particular during the loading of your login form?
-
Mar 26th, 2008, 05:48 AM
#8
Hyperactive Member
Re: [2008] Progress Bar
Yes i realise that it is a really stupid way to use a progress bar but i was just giving him an example and since i had no idea of what he wanted to use his progress bar to measure i couldn't give him an example.
-
Mar 26th, 2008, 05:50 AM
#9
Thread Starter
Lively Member
Re: [2008] Progress Bar
Not really, its just entering a user name, entering a password and clicking on sign in. Perhaps I could use the database search for the progress bar.
-
Mar 26th, 2008, 05:54 AM
#10
Hyperactive Member
Re: [2008] Progress Bar
Well if thats all your doing then you hardly need a progress bar unless the form u are loading has a video or pictures.
If you really want a loading bar then you can fake it like in my example but you might want to use a separate thread.
-
Mar 26th, 2008, 06:07 AM
#11
Thread Starter
Lively Member
Re: [2008] Progress Bar
Well its true I just want to add the progress bar to look "cool". But that code you gave me doesn't work! The progress bar just stays filled at 100% through out.
Last edited by Colin Dias; Mar 27th, 2008 at 05:18 AM.
-
Mar 26th, 2008, 06:20 AM
#12
Hyperactive Member
Re: [2008] Progress Bar
ok here is code that will work:
'add a timer to your form
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
System.Threading.Thread.Sleep(1000)
ProgressBar1.PerformStep()
System.Threading.Thread.Sleep(100)
ProgressBar1.PerformStep()
System.Threading.Thread.Sleep(100)
ProgressBar1.PerformStep()
System.Threading.Thread.Sleep(100)
ProgressBar1.PerformStep()
System.Threading.Thread.Sleep(100)
ProgressBar1.PerformStep()
System.Threading.Thread.Sleep(100)
ProgressBar1.PerformStep()
System.Threading.Thread.Sleep(100)
ProgressBar1.PerformStep()
System.Threading.Thread.Sleep(100)
ProgressBar1.PerformStep()
System.Threading.Thread.Sleep(100)
ProgressBar1.PerformStep()
System.Threading.Thread.Sleep(100)
ProgressBar1.PerformStep()
Timer1.Enabled = False
End Sub
End Class
End Sub[/CODE]
This is a very crude way of doing this and would be much better if you did it through a separate thread search "threading" but you can use it if u want to.
-
Mar 26th, 2008, 06:30 AM
#13
Thread Starter
Lively Member
Re: [2008] Progress Bar
Now the progress bar is at 0% through out... It doesnt fill up
-
Mar 26th, 2008, 06:30 AM
#14
Re: [2008] Progress Bar
Why use a timer if you're still going to sleep the UI thread? Set the timers interval to 100 milliseconds and call PerformStep once on each Tick event. Disable the timer when the ProgressBar has reached the Maximum value.
@Colin Dias,
Sorry no I dont really know much about KTH, other than that its a good university.
-
Mar 26th, 2008, 06:31 AM
#15
Re: [2008] Progress Bar
As a complete cheat if it's purely for visual things rather than actually measuring the likely time to complete you could just set its Style property to Marquee.
It obviously won't tell them in any way how long the time will take but using the idea of a Thread sleep to do this is completely barmy if you ask me.
-
Mar 26th, 2008, 06:32 AM
#16
Hyperactive Member
Re: [2008] Progress Bar
Yes my bad i dont know why i did wat i did.
-
Mar 26th, 2008, 06:33 AM
#17
Hyperactive Member
Re: [2008] Progress Bar
@stimbo yeah but he just wants a visual effect
-
Mar 26th, 2008, 06:35 AM
#18
Re: [2008] Progress Bar
but he just wants a visual effect
which the Marquee effect will give him without any effort required on his part which seems to suit.
Colin, incrementing the value by 1 and updating the progress bar is a very simple thing to do. Have you actually tried experimenting yourself or reading the documentation or even performing a basic search on this forum for Progress Bar?
Rather than simply replying with "I don't know how to do that".
-
Mar 26th, 2008, 06:52 AM
#19
Thread Starter
Lively Member
Re: [2008] Progress Bar
Took stimbo's advice. It looks fine , thanks.
-
Mar 26th, 2008, 07:01 AM
#20
Lively Member
Re: [2008] Progress Bar
If its just for aesthetic reasons you can do this:
Code:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
For i = 1 To 100 'the second number (100) must <= the Maximum property of the progress bar
ProgressBar1.Value = i
Next
End Sub
-
Mar 26th, 2008, 07:02 AM
#21
Re: [2008] Progress Bar
 Originally Posted by irishlad
If its just for aesthetic reasons you can do this:
Code:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
For i = 1 To 100 'the second number (100) must <= the Maximum property of the progress bar
ProgressBar1.Value = i
Next
End Sub
Actually, that wont work. Take a look at post #5.
-
Mar 27th, 2008, 01:17 AM
#22
Thread Starter
Lively Member
Last edited by Colin Dias; Mar 27th, 2008 at 05:19 AM.
-
Mar 27th, 2008, 01:31 AM
#23
Re: [2008] Progress Bar
 Originally Posted by Colin Dias
How do you change the profile name?
What profile are you talking about?
-
Mar 27th, 2008, 02:08 AM
#24
Thread Starter
Lively Member
Last edited by Colin Dias; Mar 27th, 2008 at 05:18 AM.
-
Mar 27th, 2008, 03:29 AM
#25
Thread Starter
Lively Member
Re: [2008] Progress Bar
 Originally Posted by irishlad
If its just for aesthetic reasons you can do this:
Code:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
For i = 1 To 100
ProgressBar1.Value = i
Next
End Sub
Actually this worked the best. I used it in the button click event. I used a delay in the loop to make it look better.
Code:
For i = 1 To 100 'the second number (100) must <= the Maximum property of the progress bar
ProgressBar1.Value = i
System.Threading.Thread.Sleep(25)
Next
Last edited by Colin Dias; Mar 27th, 2008 at 03:35 AM.
-
Mar 27th, 2008, 05:04 AM
#26
Re: [2008] Progress Bar
What has your VBForums profile got to do with ProgressBars or VB.NET? Please keep each thread to one topic and one relevant topic.
I also have to say that making your application load more slowly by sleeping the UI thread for 2.5 seconds so that you can show a ProgressBar that "looks cool" is really not a good idea. I would sooner have the app load faster. I think I speak for pretty much all users in saying that.
-
Mar 28th, 2008, 07:08 AM
#27
Hyperactive Member
Re: [2008] Progress Bar
Jmc you might find that more vb beginners (like me) prefer their application to look 'cool' with visual effects i know i have done a fake loading bar just for an effect.
-
Mar 28th, 2008, 07:37 AM
#28
Member
Re: [2008] Progress Bar
ok propably you r newbie like me and you dont understand the steps from pro's... i try to help you step by step
i did it like this : and works grate
first you need 2 forms :
1) frmstart.vb
2) LoginForm.vb
first you need the code to show login form
Code:
Private Sub frmStart_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
LoginForm.MdiParent = Me
LoginForm.Show()
End Sub
in your LoginForm.vb you need
1) UsernameTextBox + label if you want
2) PasswordTextBox + label if you want
3) ProgressBar1
4) Timer1
5) label1
after that you place the code in the form for the timer
Code:
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
ProgressBar1.Value += 2
If ProgressBar1.Value <= 30 Then
Label1.Text = "Initialized Application ....."
ElseIf ProgressBar1.Value <= 50 Then
Label1.Text = "Loading Data Component ....."
ElseIf ProgressBar1.Value <= 70 Then
Label1.Text = "Integration Database ...."
ElseIf ProgressBar1.Value <= 100 Then
Label1.Text = "Please Wait ...."
End If
If ProgressBar1.Value = 100 Then
Timer1.Enabled = False
'ηταν στη θεση (3)
Me.Hide()
frmStart.ToolStripStatusLabel1.Text = UsernameTextBox.Text
frmStart.ToolStripStatusLabel2.Text = "Χρήστης :"
frmStart.MenuStrip1.Enabled = True
End If
End Sub
and finaly you call timer from button enter
*NOTE* you call the timer after the sucside login
Code:
Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
Dim sql = "SELECT name ,code FROM SC WHERE name='" & UsernameTextBox.Text & "' AND code='" & PasswordTextBox.Text & "'"
cmd = New OleDbCommand(sql, conn)
conn.Open()
Dim dr As OleDbDataReader = cmd.ExecuteReader
Try
If dr.Read = False Then
MessageBox.Show("Λάθος Χρήστης ή Κωδικός. Παρακαλώ προσπαθήστε πάλι...")
Else
'θεση (3)
Timer1.Start()
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
conn.Close()
End Sub
-
Mar 28th, 2008, 07:44 AM
#29
Member
Last edited by Chrisad; Mar 28th, 2008 at 07:49 AM.
-
Mar 28th, 2008, 07:45 AM
#30
Member
Last edited by Chrisad; Mar 28th, 2008 at 07:49 AM.
-
Mar 28th, 2008, 07:46 AM
#31
Member
Last edited by Chrisad; Mar 28th, 2008 at 07:50 AM.
-
Mar 28th, 2008, 07:49 AM
#32
Re: [2008] Progress Bar
Whats with all the empty posts Chrisad?
-
Mar 28th, 2008, 07:50 AM
#33
Re: [2008] Progress Bar
I don't want to offend, but it's completely and unforgiveably idiotic to slow down a program just so your program 'looks' like it's doing something. The best way to make a user happy is to minimise the amount of time they have to spend waiting on your application to do something.
A progress bar is only useful when you perform large routines or calculations. This is so that the user knows that something is actually happening and that the computer hasn't frozen up.
So if you're looking for 'coolness', then find other ways of doing it. And for goodness sake don't use the sleep command on a thread. Usage like the type above make me think it should be banned.
@Atheist: They aren't empty, just full of a bunch of screenshots that show every step in his progress bar.
Last edited by MaximilianMayrhofer; Mar 28th, 2008 at 07:59 AM.
-
Mar 28th, 2008, 07:55 AM
#34
Re: [2008] Progress Bar
vb.net Code:
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
ProgressBar1.Value += 2
If ProgressBar1.Value <= 30 Then
Label1.Text = "Initialized Application ....."
ElseIf ProgressBar1.Value <= 50 Then
Label1.Text = "Loading Data Component ....."
ElseIf ProgressBar1.Value <= 70 Then
Label1.Text = "Integration Database ...."
ElseIf ProgressBar1.Value <= 100 Then
Label1.Text = "Please Wait ...."
End If
If ProgressBar1.Value = 100 Then
Timer1.Enabled = False
'ηταν στη θεση (3)
Me.Hide()
frmStart.ToolStripStatusLabel1.Text = UsernameTextBox.Text
frmStart.ToolStripStatusLabel2.Text = "Χρήστης :"
frmStart.MenuStrip1.Enabled = True
End If
End Sub
Why are you using Me.Hide()? It's an unnecessary waste of system resources. Once the logon is successful, the logon form should be disposed of. As best practice, users should be validated even before the main application loads.
-
Mar 28th, 2008, 08:14 AM
#35
Re: [2008] Progress Bar
This thread is all about what's considered "cool" and not what's good. If you want to be a real software developer then you had best realise that writing good code is what's cool. The rest is just window dressing that is worse than pointless because it makes your app run slower. If that's what you want then logic has no place here.
-
Mar 29th, 2008, 12:37 AM
#36
Thread Starter
Lively Member
Re: [2008] Progress Bar
The application was taking a while to load up so I wanted to add a progress bar to show the user that the program was not freezing up.
Alternatively I thought of using an hour glass for the pointer.
Code:
Button1.Cursor = Cursors.WaitCursor
Used in the login button's click event.
Last edited by Colin Dias; Mar 29th, 2008 at 12:48 AM.
-
Mar 29th, 2008, 01:46 AM
#37
Re: [2008] Progress Bar
 Originally Posted by Colin Dias
The application was taking a while to load up so I wanted to add a progress bar to show the user that the program was not freezing up.
Alternatively I thought of using an hour glass for the pointer.
Code:
Button1.Cursor = Cursors.WaitCursor
Used in the login button's click event.
If you want an indicator of activity, rather than actual progress, then just set the Style property to Marquee and do nothing else.
Last edited by jmcilhinney; Mar 29th, 2008 at 01:54 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|