How do i get a loading bar similar to those used on installations etc?
I need this for a prank app i am making.
Printable View
How do i get a loading bar similar to those used on installations etc?
I need this for a prank app i am making.
Do you mean "progress bar"? If yes then try one from MS Windows Common Control (select it from components).
I forget who wrote this a while back, but it is kind of cool. Add a picturebox and a timer control.
VB Code:
Option Explicit Private Const PI As Double = 3.14159265358979 Private Sub Form_Load() PicProcess.ForeColor = vbBlue PicProcess.AutoRedraw = True PicProcess.BorderStyle = 0 PicProcess.Appearance = 0 PicProcess.BackColor = Me.BackColor TmrProcess.Interval = 10 TmrProcess.Enabled = True End Sub Private Sub picProcess_Resize() PicProcess.Cls End Sub Private Sub tmrProcess_Timer() Static PrevPos As Single, Direction As Boolean Dim BHeight As Single, Pos As Single, K As Single Dim BarLen As Single BarLen = PicProcess.ScaleWidth * 0.2 BHeight = PicProcess.ScaleHeight - 15 PicProcess.Circle (BHeight / 2, BHeight / 2), BHeight / 2, 0, PI * 0.5, PI * 1.5 PicProcess.Circle (PicProcess.ScaleWidth - BHeight / 2 - 15, BHeight / 2), BHeight / 2, 0, PI * 1.5, PI * 0.5 PicProcess.Line (BHeight / 2, 0)-(PicProcess.ScaleWidth - BHeight / 2, 0), 0 PicProcess.Line (BHeight / 2 - 15, BHeight)-(PicProcess.ScaleWidth - BHeight / 2, BHeight), 0 If PrevPos = 0 Then PrevPos = BHeight / 2 If Not Direction Then Pos = PrevPos + PicProcess.ScaleWidth * 0.015 If Pos + BarLen > PicProcess.ScaleWidth - BHeight / 2 - 15 Then Direction = True Else Pos = PrevPos - PicProcess.ScaleWidth * 0.015 If Pos < BHeight / 2 Then Direction = False End If PicProcess.Line (PrevPos, 30)-(PrevPos + BarLen, BHeight - 30), PicProcess.BackColor, BF PicProcess.Line (Pos, 30)-(Pos + BarLen, BHeight - 30), , BF For K = Pos To Pos + BarLen Step PicProcess.ScaleWidth * 0.05 PicProcess.Line (K, 30)-(K, BHeight - 15), PicProcess.BackColor Next K PrevPos = Pos End Sub
That's really cool thing DG. :thumb:
Right, i've done that, but how do i get it to increase if i retrieve a percentage from somewhere and make it increase/decrease to that point?Quote:
Originally Posted by RhinoBull
It doesn't fill. Set the interval to 100 (or more) to get it to move 10 times per second. It swivels back and forth while it's running. If you want something to fill, you'd have to use a progress bar.
How do i set the interval (on the microsoft common control)?
Depends on what "somewhere" is so what is it?Quote:
Originally Posted by ajames
You don't. Just set tmrProcess.Interval=100 in the form load. You also need tmrProcess.Enabled=True to actually start the timer. In my code, I set them both in the properties of the Timer.
Somewhere could be a textbox, then a button to make it jump to that point.Quote:
Originally Posted by RhinoBull
Also, could i make it start at 0% and increase all the way to the top?
Sorry, it's not clear. You see if you want to show progress of some process you must know at least the size of that something and also way of looping so you can increment some counter.
So, if you can give a little more details then I'd happy to post sample code for you.
You can add a click event to this to change the position.
VB Code:
Option Explicit Private Declare Sub Sleep Lib "kernel32.dll" (ByVal dwMilliseconds As Long) Private Sub Form_Activate() ProgressBar1.Min = 0 ProgressBar1.Max = 100 ProgressBar1.Value = 0 ProgressBar1.Enabled = True Dim x As Integer Dim q As Long For x = 0 To 100 DoEvents ProgressBar1.Value = x Sleep 50 Next x MsgBox "Done" Unload Me End Sub
Dglienna's code worked fine. Thanks to all.