Results 1 to 13 of 13

Thread: [RESOLVED] Loading bar

  1. #1

    Thread Starter
    Addicted Member ajames's Avatar
    Join Date
    Mar 2005
    Location
    Wales, UK
    Posts
    178

    Resolved [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.

  2. #2

  3. #3
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    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:
    1. Option Explicit
    2.  
    3. Private Const PI As Double = 3.14159265358979
    4.  
    5. Private Sub Form_Load()
    6.     PicProcess.ForeColor = vbBlue
    7.     PicProcess.AutoRedraw = True
    8.     PicProcess.BorderStyle = 0
    9.     PicProcess.Appearance = 0
    10.     PicProcess.BackColor = Me.BackColor
    11.    
    12.     TmrProcess.Interval = 10
    13.     TmrProcess.Enabled = True
    14. End Sub
    15.  
    16. Private Sub picProcess_Resize()
    17.     PicProcess.Cls
    18. End Sub
    19.  
    20. Private Sub tmrProcess_Timer()
    21.     Static PrevPos As Single, Direction As Boolean
    22.         Dim BHeight As Single, Pos As Single, K As Single
    23.     Dim BarLen As Single
    24.     BarLen = PicProcess.ScaleWidth * 0.2
    25.     BHeight = PicProcess.ScaleHeight - 15
    26.    
    27.     PicProcess.Circle (BHeight / 2, BHeight / 2), BHeight / 2, 0, PI * 0.5, PI * 1.5
    28.     PicProcess.Circle (PicProcess.ScaleWidth - BHeight / 2 - 15, BHeight / 2), BHeight / 2, 0, PI * 1.5, PI * 0.5
    29.     PicProcess.Line (BHeight / 2, 0)-(PicProcess.ScaleWidth - BHeight / 2, 0), 0
    30.     PicProcess.Line (BHeight / 2 - 15, BHeight)-(PicProcess.ScaleWidth - BHeight / 2, BHeight), 0
    31.    
    32.     If PrevPos = 0 Then PrevPos = BHeight / 2
    33.    
    34.     If Not Direction Then
    35.         Pos = PrevPos + PicProcess.ScaleWidth * 0.015
    36.         If Pos + BarLen > PicProcess.ScaleWidth - BHeight / 2 - 15 Then Direction = True
    37.     Else
    38.         Pos = PrevPos - PicProcess.ScaleWidth * 0.015
    39.         If Pos < BHeight / 2 Then Direction = False
    40.     End If
    41.         PicProcess.Line (PrevPos, 30)-(PrevPos + BarLen, BHeight - 30), PicProcess.BackColor, BF
    42.     PicProcess.Line (Pos, 30)-(Pos + BarLen, BHeight - 30), , BF
    43.    
    44.     For K = Pos To Pos + BarLen Step PicProcess.ScaleWidth * 0.05
    45.         PicProcess.Line (K, 30)-(K, BHeight - 15), PicProcess.BackColor
    46.     Next K
    47.    
    48.     PrevPos = Pos
    49. End Sub

  4. #4
    Smitten by reality Harsh Gupta's Avatar
    Join Date
    Feb 2005
    Posts
    2,938

    Re: Loading bar

    That's really cool thing DG.
    Show Appreciation. Rate Posts.

  5. #5

    Thread Starter
    Addicted Member ajames's Avatar
    Join Date
    Mar 2005
    Location
    Wales, UK
    Posts
    178

    Re: Loading bar

    Quote 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?

  6. #6
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    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.

  7. #7

    Thread Starter
    Addicted Member ajames's Avatar
    Join Date
    Mar 2005
    Location
    Wales, UK
    Posts
    178

    Re: Loading bar

    How do i set the interval (on the microsoft common control)?

  8. #8

  9. #9
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    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.

  10. #10

    Thread Starter
    Addicted Member ajames's Avatar
    Join Date
    Mar 2005
    Location
    Wales, UK
    Posts
    178

    Re: Loading bar

    Quote 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?

  11. #11
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    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.

  12. #12
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Loading bar

    You can add a click event to this to change the position.
    VB Code:
    1. Option Explicit
    2.  
    3. Private Declare Sub Sleep Lib "kernel32.dll" (ByVal dwMilliseconds As Long)
    4.  
    5. Private Sub Form_Activate()
    6.   ProgressBar1.Min = 0
    7.   ProgressBar1.Max = 100
    8.   ProgressBar1.Value = 0
    9.   ProgressBar1.Enabled = True
    10.   Dim x As Integer
    11.   Dim q As Long
    12.   For x = 0 To 100
    13.     DoEvents
    14.     ProgressBar1.Value = x
    15.     Sleep 50
    16.   Next x
    17.   MsgBox "Done"
    18.   Unload Me
    19. End Sub

  13. #13

    Thread Starter
    Addicted Member ajames's Avatar
    Join Date
    Mar 2005
    Location
    Wales, UK
    Posts
    178

    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
  •  



Click Here to Expand Forum to Full Width