|
-
Dec 31st, 2005, 03:43 PM
#1
Thread Starter
Addicted Member
[RESOLVED] Loading bar
How do i get a loading bar similar to those used on installations etc?
I need this for a prank app i am making.
-
Dec 31st, 2005, 03:52 PM
#2
Re: Loading bar
Do you mean "progress bar"? If yes then try one from MS Windows Common Control (select it from components).
-
Dec 31st, 2005, 03:55 PM
#3
Re: Loading bar
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
-
Dec 31st, 2005, 04:02 PM
#4
Re: Loading bar
That's really cool thing DG.
-
Jan 1st, 2006, 04:06 PM
#5
Thread Starter
Addicted Member
Re: Loading bar
 Originally Posted by RhinoBull
Do you mean "progress bar"? If yes then try one from MS Windows Common Control (select it from components).
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?
-
Jan 1st, 2006, 04:09 PM
#6
Re: Loading bar
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.
-
Jan 1st, 2006, 04:14 PM
#7
Thread Starter
Addicted Member
Re: Loading bar
How do i set the interval (on the microsoft common control)?
-
Jan 1st, 2006, 04:19 PM
#8
Re: Loading bar
 Originally Posted by ajames
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?
Depends on what "somewhere" is so what is it?
-
Jan 1st, 2006, 04:20 PM
#9
Re: Loading bar
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.
-
Jan 1st, 2006, 04:23 PM
#10
Thread Starter
Addicted Member
Re: Loading bar
 Originally Posted by RhinoBull
Depends on what "somewhere" is so what is it?
Somewhere could be a textbox, then a button to make it jump to that point.
Also, could i make it start at 0% and increase all the way to the top?
-
Jan 1st, 2006, 04:29 PM
#11
Re: Loading bar
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.
-
Jan 1st, 2006, 04:30 PM
#12
Re: Loading bar
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
-
Jan 1st, 2006, 04:48 PM
#13
Thread Starter
Addicted Member
Re: Loading bar
Dglienna's code worked fine. Thanks to all.
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
|