Can someone post some code on how the progress bar will work when the login screen is loading up ?
Printable View
Can someone post some code on how the progress bar will work when the login screen is loading up ?
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.
I dont know how to do that
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
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.
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.
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?
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.
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.
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.
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.
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.
Now the progress bar is at 0% through out... It doesnt fill up
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.
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.
Yes my bad i dont know why i did wat i did.
@stimbo yeah but he just wants a visual effect :D
which the Marquee effect will give him without any effort required on his part which seems to suit. :thumb:Quote:
but he just wants a visual effect
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".
Took stimbo's advice. It looks fine , thanks.
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.Quote:
Originally Posted by irishlad
....
What profile are you talking about?Quote:
Originally Posted by Colin Dias
....
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.Quote:
Originally Posted by irishlad
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
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.
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.
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
and finaly you call timer from button enterCode: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
*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
Whats with all the empty posts Chrisad?
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.
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.
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.
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.Used in the login button's click event.Code:Button1.Cursor = Cursors.WaitCursor
If you want an indicator of activity, rather than actual progress, then just set the Style property to Marquee and do nothing else.Quote:
Originally Posted by Colin Dias