Results 1 to 16 of 16

Thread: Progress Bar, with label on top?

  1. #1

    Thread Starter
    Frenzied Member I_Love_My_Vans's Avatar
    Join Date
    Jan 2005
    Location
    In the PHP compiler
    Posts
    1,275

    Progress Bar, with label on top?

    Why can i not put a label on top of a progress bar?

    Any ideas. solutions?

    ILMV

  2. #2
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: Progress Bar, with label on top?

    Quote Originally Posted by I_Love_My_Vans
    Why can i not put a label on top of a progress bar?

    Any ideas. solutions?

    ILMV

    Take a look at this post
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


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

    Re: Progress Bar, with label on top?

    good timing mark........i was about to post the similar thing.........but surely ur code works better than that
    Show Appreciation. Rate Posts.

  4. #4
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Progress Bar, with label on top?

    The simple reason you can't put a Label on top of a ProgressBar is because a Label is windowless, which means that VB draws the text directly on the Form. A windowless control can never be above a windowed control (unless the control is a container like the PictureBox or Frame of course).

    Mark showed you how you can replace the ProgressBar with a PictureBox but if you still want to use the ProgressBar the following code will draw text on it.
    VB Code:
    1. Private Declare Function GetDC Lib "user32.dll" ( _
    2.  ByVal hWnd As Long) As Long
    3.  
    4. Private Declare Function ReleaseDC Lib "user32.dll" ( _
    5.  ByVal hWnd As Long, _
    6.  ByVal hDC As Long) As Long
    7.  
    8. Private Declare Function DrawText _
    9.  Lib "user32.dll" Alias "DrawTextA" ( _
    10.  ByVal hDC As Long, _
    11.  ByVal lpStr As String, _
    12.  ByVal nCount As Long, _
    13.  ByRef lpRect As RECT, _
    14.  ByVal wFormat As Long) As Long
    15.  
    16. Private Declare Function SetBkMode Lib "gdi32.dll" ( _
    17.  ByVal hDC As Long, _
    18.  ByVal nBkMode As Long) As Long
    19.  
    20. Private Declare Function GetClientRect _
    21.  Lib "user32.dll" ( _
    22.  ByVal hWnd As Long, _
    23.  ByRef lpRect As RECT) As Long
    24.  
    25. Private Type RECT
    26.     Left As Long
    27.     Top As Long
    28.     Right As Long
    29.     Bottom As Long
    30. End Type
    31.  
    32. Private Const TRANSPARENT As Long = 1
    33. Private Const DT_CENTER As Long = &H1
    34.  
    35. Public Sub TextOnProgress(pb As ProgressBar, ByVal sText As String)
    36.     Dim hDC As Long
    37.     Dim r As RECT
    38.    
    39.     hDC = GetDC(pb.hWnd)
    40.     Call SetBkMode(hDC, TRANSPARENT)
    41.     Call GetClientRect(pb.hWnd, r)
    42.     Call DrawText(hDC, sText, -1&, r, DT_CENTER)
    43.     Call ReleaseDC(pb.hWnd, hDC)
    44. End Sub
    Simply call the TextOnProgress this way:
    VB Code:
    1. Call TextOnProgress(ProgressBar1, "The text to show")

  5. #5
    Frenzied Member wiz126's Avatar
    Join Date
    Jul 2005
    Location
    Mars,Milky Way... Chit Chat Posts: 5,733
    Posts
    1,080

    Re: Progress Bar, with label on top?

    check this link out this component its a progresbar with alot more options then the stink defult bar

    http://www.vbcity.com/mbgallery/defa...=mbprogressbar
    1) If your post has been adequately answered please click in your post on "Mark Thread Resolved".
    2) If someone has been useful to you please show your respect by rating their posts.
    3) Please use [highlight="VB"] 'your code goes in here [/highlight] tags when posting code.
    4) Before posting your question, make sure you checked this links:
    MICROSOFT MSDN -- VB FORUMS SEARCH

    5)Support Classic VB - A PETITION TO MICROSOFT

    ___________________________________________________________________________________
    THINGS TO KNOW ABOUT VB: || VB Examples/Demos
    What are Classes?
    || -
    Where to place a sub/function?(global) || Webbrowser control

  6. #6
    Junior Member
    Join Date
    Dec 2011
    Posts
    20

    Re: Progress Bar, with label on top?

    Thanks a lot for this great tips Joacim Andersson :-)
    But i have a problem with your code, if i enter a changing text like this
    Code:
    Private Sub Form_Load()
     For i = 1 To 100 Step 10
      
      ProgressBar1.Value = i
      TextOnProgress ProgressBar1, Trim(Str(i))
      DoEvents
      Sleep 1000
     Next
     
    End Sub
    the new value is overwriting on the old value, and after several writing it's really impossible to read :-(
    Have you a way for fix that ?

  7. #7
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,109

    Re: Progress Bar, with label on top?

    This thread is 12 years old. Nobody who participated has been here for a few years. Therefore, it would be better if you started a new thread with the question, as you aren't likely to get any useful responses in this thread.
    My usual boring signature: Nothing

  8. #8
    Junior Member
    Join Date
    Dec 2011
    Posts
    20

    Re: Progress Bar, with label on top?

    Aaah ok...
    Thanks for your answer

  9. #9
    Frenzied Member
    Join Date
    Dec 2008
    Location
    Melbourne Australia
    Posts
    1,487

    Re: Progress Bar, with label on top?

    I don't think you have created the fresh thread yet ?
    In the meantime, this may help if you (Andre) are looking for text 'over' (appearing to be on top) of the progress bar -
    http://www.planet-source-code.com/vb...25863&lngWId=1
    The author has been around the block for a long time.

    Rob

  10. #10
    Junior Member
    Join Date
    Dec 2011
    Posts
    20

    Re: Progress Bar, with label on top?

    No i have not again create the new thread
    Thanks for your answer Bobbles, unfortunately the link of the zip is broken :-(

    Edit : But i have found the solution thanks to this thread
    http://www.vbforums.com/showthread.p...=1#post3574251

    In fact a simple "pb.Refresh" is needed
    Code:
    Public Sub TextOnProgress(pb As ProgressBar, ByVal sText As String)
    
        Dim hDC As Long
        Dim r As RECT
        
        hDC = GetDC(pb.hwnd)
        pb.Refresh
        SetBkMode hDC, TRANSPARENT
        GetClientRect pb.hwnd, r
        SetTextColor hDC, &HFFFFFF
        DrawText hDC, sText, -1&, r, DT_CENTER
        ReleaseDC pb.hwnd, hDC
            
    End Sub
    Thanks for your help
    Have a good day
    Last edited by AndreBernard; Sep 26th, 2017 at 03:15 AM.

  11. #11
    Frenzied Member
    Join Date
    Dec 2008
    Location
    Melbourne Australia
    Posts
    1,487

    Re: Progress Bar, with label on top?

    Quote Originally Posted by AndreBernard View Post
    No i have not again create the new thread
    Thanks for your answer Bobbles, unfortunately the link of the zip is broken
    I have attached the PSC download file
    Rob
    Attached Files Attached Files

  12. #12
    Junior Member
    Join Date
    Dec 2011
    Posts
    20

    Re: Progress Bar, with label on top?

    Thanks a lot Bobbles
    Have a good day

  13. #13
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Progress Bar, with label on top?

    Quote Originally Posted by AndreBernard View Post
    In fact a simple "pb.Refresh" is needed
    Code:
    Public Sub TextOnProgress(pb As ProgressBar, ByVal sText As String)
    
        Dim hDC As Long
        Dim r As RECT
        
        hDC = GetDC(pb.hwnd)
        pb.Refresh
        SetBkMode hDC, TRANSPARENT
        GetClientRect pb.hwnd, r
        SetTextColor hDC, &HFFFFFF
        DrawText hDC, sText, -1&, r, DT_CENTER
        ReleaseDC pb.hwnd, hDC
            
    End Sub
    FYI: Typically, you should not retrieve the hDC before you refresh. Refreshing could potentially result in a change of hDC depending on the actions performed by the control during its Refresh method.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  14. #14
    Junior Member
    Join Date
    Dec 2011
    Posts
    20

    Re: Progress Bar, with label on top?

    Aaaah ok
    Thanks

  15. #15
    Fanatic Member
    Join Date
    Aug 2013
    Posts
    806

    Re: Progress Bar, with label on top?

    Just a quick reminder that while you can do this, you probably shouldn't do this. Microsoft explicitly discourages text on top of progress bars because it can be very difficult to read, especially on systems with non-standard themes. From that link:

    - Do not embed text, such as a percentage, in the progress bar itself. This is not accessible.
    - If the progress bar is contained in the status bar, put any corresponding message text to its left in the status bar.
    Check out PhotoDemon, a pro-grade photo editor written completely in VB6. (Full source available at GitHub.)

  16. #16
    Junior Member
    Join Date
    Dec 2011
    Posts
    20

    Re: Progress Bar, with label on top?

    Yes you have right, i have see that sometime :-)

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