Why can i not put a label on top of a progress bar?
Any ideas. solutions?
ILMV
Printable View
Why can i not put a label on top of a progress bar?
Any ideas. solutions?
ILMV
Quote:
Originally Posted by I_Love_My_Vans
Take a look at this post
good timing mark........i was about to post the similar thing.........but surely ur code works better than that :thumb:
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.Simply call the TextOnProgress this way:VB Code:
Private Declare Function GetDC Lib "user32.dll" ( _ ByVal hWnd As Long) As Long Private Declare Function ReleaseDC Lib "user32.dll" ( _ ByVal hWnd As Long, _ ByVal hDC As Long) As Long Private Declare Function DrawText _ Lib "user32.dll" Alias "DrawTextA" ( _ ByVal hDC As Long, _ ByVal lpStr As String, _ ByVal nCount As Long, _ ByRef lpRect As RECT, _ ByVal wFormat As Long) As Long Private Declare Function SetBkMode Lib "gdi32.dll" ( _ ByVal hDC As Long, _ ByVal nBkMode As Long) As Long Private Declare Function GetClientRect _ Lib "user32.dll" ( _ ByVal hWnd As Long, _ ByRef lpRect As RECT) As Long Private Type RECT Left As Long Top As Long Right As Long Bottom As Long End Type Private Const TRANSPARENT As Long = 1 Private Const DT_CENTER As Long = &H1 Public Sub TextOnProgress(pb As ProgressBar, ByVal sText As String) Dim hDC As Long Dim r As RECT hDC = GetDC(pb.hWnd) Call SetBkMode(hDC, TRANSPARENT) Call GetClientRect(pb.hWnd, r) Call DrawText(hDC, sText, -1&, r, DT_CENTER) Call ReleaseDC(pb.hWnd, hDC) End SubVB Code:
Call TextOnProgress(ProgressBar1, "The text to show")
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
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
the new value is overwriting on the old value, and after several writing it's really impossible to read :-(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
Have you a way for fix that ?
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.
Aaah ok...
Thanks for your answer
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
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 :)
Thanks for your help :cool: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
Have a good day
Thanks a lot Bobbles
Have a good day
Aaaah ok
Thanks
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:
Quote:
- 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.
Yes you have right, i have see that sometime :-)