Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > Interface and Graphics > Alternative To Progressbar


Reply
 
Thread Tools Display Modes
  #1  
Old 08-24-2005, 09:12 PM
Lintz's Avatar
Lintz Lintz is offline
Senior Contributor
 
Join Date: Mar 2003
Location: The 19th Hole
Posts: 989
Default Alternative To Progressbar


I'm using a picturebox as an alternative to a progressbar however when I update it it's not smooth like a progressbar. Is this just the way the picturebox works or can I "smooth" the updating?

Below is the code I'm using.
Code:
Option Explicit
Dim f As PictureBox
Dim i As Long
Private Sub Form_Load()
Me.Show

   Set f = tbFlood
   
  'initialize the control by setting:
  'white (the text colour)
  'black (the flood panel colour)
  'not Xor pen
  'solid fill
   f.Cls
   f.BackColor = &HFFFFFF
   f.ForeColor = &H800000
   f.DrawMode = 10
   f.FillStyle = 0
   

   f.ScaleWidth = 1000 'upperLimit
     
   f.Cls
   f.Visible = True
   
For i = 0 To 10000

UpdateProgress 1000, i

Next

End Sub


Public Sub UpdateProgress(upperLimit As Double, progress As Long)

Dim sProgressMessage As String

sProgressMessage = "Importing Details...."
   Dim pc As String
   
   If progress <= upperLimit Then

     If progress > tbFlood.ScaleWidth Then progress = tbFlood.ScaleWidth
         
     tbFlood.Cls
     tbFlood.ScaleWidth = upperLimit
        
    'format the progress into a percentage string to display
     pc = Format$(CLng((progress / tbFlood.ScaleWidth) * 100)) + "%"
         
     DoEvents
         
    'calculate the string's X & Y coordinates
    'in the PictureBox ... here, left justified and offset slightly
     tbFlood.CurrentX = 2
     tbFlood.CurrentY = (tbFlood.ScaleHeight - tbFlood.TextHeight(sProgressMessage)) \ 2
         
    'print the percentage string in the text colour
     DoEvents
     tbFlood.Print sProgressMessage & " " & pc
        
    'print the flood bar to the new progress length in the line colour
     tbFlood.Line (0, 0)-(progress, tbFlood.ScaleHeight), tbFlood.ForeColor, BF
     
    'without this Refresh, the progress won't update
    tbFlood.Refresh
   
  End If

End Sub
Reply With Quote
  #2  
Old 08-24-2005, 09:42 PM
OnErr0r's Avatar
OnErr0r OnErr0r is offline
Obsessive OPtimizer

Administrator
* Guru *
 
Join Date: Jun 2002
Location: Debug Window
Posts: 13,685
Default

Try turning AutoRedraw on and doing away with .Refresh. That should cut way down on flicker.

http://www.xtremevbtalk.com/showpost...24&postcount=3
__________________
Quis custodiet ipsos custodues.
Reply With Quote
  #3  
Old 08-24-2005, 11:12 PM
the master's Avatar
the master the master is offline
Tachikoma
 
Join Date: Mar 2003
Location: Mansfield, UK
Posts: 4,594
Default

i always thought you only used .refresh when auto redraw is on. i thought it wiped your image if it wasnt.

i think you still need to refresh though because with auto redraw it will draw everything but you wont see it until its refreshed by .refresh or .cls or even changing the backbolor seems to work

another good thing about autoredraw that might be worth mentioning as you seem not to have used it before. if another window goes over your progress bar or anything happens so you cant see it on the screen and autoredraw is turned off, it will wipe whatever you draw on it. autoredraw will keep all the information but it slows things down a lot. if you plan to update your progress bar a few times a second then you would notice a difference
__________________
"That which seems simple is often overlooked" ~ me
Halloween Special FX
Web Hosting from Spook Technologies
Reply With Quote
  #4  
Old 08-24-2005, 11:36 PM
OnErr0r's Avatar
OnErr0r OnErr0r is offline
Obsessive OPtimizer

Administrator
* Guru *
 
Join Date: Jun 2002
Location: Debug Window
Posts: 13,685
Default

In this case .Refresh is not needed. Take a look:
Attached Files
File Type: zip frmTest.zip (1,002 Bytes, 19 views)
__________________
Quis custodiet ipsos custodues.
Reply With Quote
  #5  
Old 08-25-2005, 02:02 AM
Lintz's Avatar
Lintz Lintz is offline
Senior Contributor
 
Join Date: Mar 2003
Location: The 19th Hole
Posts: 989
Default

Thanks. I got rid of the DoEvents and the flickering stopped.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->