Windows Develop Bookmark and Share   
 index > Windows Forms General > backcolor=transparent
 

backcolor=transparent

I have placed a progressbar on a form. I want a text be displayed on the progress bar as well. Since that feature is not found on the progressbar control I placed a label on it. However, how can I make the label's background color transparent so that the label is visible properly. I tried choosing the label-backcolor to transparent; but it did not work.
RKBNAIR  Tuesday, December 06, 2005 11:18 PM
Hi,

There are two reasons why your approach isn't working:

1. ProgressBar is not a ContainerControl. That means that it if you a put label on a ProgressBar in the designer, the label will not become a child of the ProgressBar, but rather that of the first container the mouse position is on that is a ContainerControl. In this case that will probably be the form. That means that if the label is set to transparant, it will draw the parent's rectangle underneath the label. In this case the form's rectangle is drawn, instead of the ProgressBar's.

2. ProgressBar uses an alternative way of painting. Overriding OnPaintBackGround and OnPaint will do nothing. Internally the progress bar uses PBM_* messages, and these will paint the progress bar.

Did all of that make some sense?

If you are using VS 2005, there's an easy solution: go to the ProgressBarRenderer class in the documentation, which contains an example on how to paint custom ProgressBars. Just add your DrawString in the paint method, and you're done!

If you're still using VS 2003, let me know so I can find an alternative solution.

Hope this answers your question.
Jelle van der Beek2  Wednesday, December 07, 2005 9:05 AM

The ProgressBar doesn’t support custom painting for you to put a transparent label on it, but you can create your own progress bar with text in it, is really simple.

 

See the example:

http://www.codeproject.com/cs/miscctrl/ExtendedProgressbar.asp

 

Eli Gazit  Wednesday, December 07, 2005 9:29 AM
Hi,

There are two reasons why your approach isn't working:

1. ProgressBar is not a ContainerControl. That means that it if you a put label on a ProgressBar in the designer, the label will not become a child of the ProgressBar, but rather that of the first container the mouse position is on that is a ContainerControl. In this case that will probably be the form. That means that if the label is set to transparant, it will draw the parent's rectangle underneath the label. In this case the form's rectangle is drawn, instead of the ProgressBar's.

2. ProgressBar uses an alternative way of painting. Overriding OnPaintBackGround and OnPaint will do nothing. Internally the progress bar uses PBM_* messages, and these will paint the progress bar.

Did all of that make some sense?

If you are using VS 2005, there's an easy solution: go to the ProgressBarRenderer class in the documentation, which contains an example on how to paint custom ProgressBars. Just add your DrawString in the paint method, and you're done!

If you're still using VS 2003, let me know so I can find an alternative solution.

Hope this answers your question.
Jelle van der Beek2  Wednesday, December 07, 2005 9:05 AM

The ProgressBar doesn’t support custom painting for you to put a transparent label on it, but you can create your own progress bar with text in it, is really simple.

 

See the example:

http://www.codeproject.com/cs/miscctrl/ExtendedProgressbar.asp

 

Eli Gazit  Wednesday, December 07, 2005 9:29 AM
I have a related problem.

I would like to use the ProgressBar on a panel that has a background color different from the standard Control grey...
In this case the nicely rounded corners of the ProgressBar do not seem to care what background color I specify, resulting in some rather ugly white square angles at each corner of the control.

When experimenting with the ProgressBarRenderer I got the same corner artefacts for those render methods.

Is there a solution to this problem other than writing my own ProgressBar?
I can't imagine I am the only one hoping to use the ProgressBar with background colors other than Control grey, without issues?
FredrikHall  Thursday, December 15, 2005 3:55 PM

Hey freka! I just searched for your message for about 20 minutes :). Could you please repost your question in a new thread? If we continue this thread you are missing out on all the other who see a new unanswered thread and would like to help out!

I don't have time to answer your question now, maybe later in the new thread. Thanks a lot!

Jelle van der Beek2  Friday, December 16, 2005 9:54 AM

You can use google to search for other answers

Custom Search

More Threads

• Recursive call
• Custom Controls are not showing up in Toolbox. VS2005
• How to detect when a form gets activated/deactivated/closed/minimized etc
• Ip adress switch
• How to scroll into view in Splitcontainer for desired controls?
• WebBrowser - strange behaviour using hyperlinks
• Position of Insertion Point for Selection
• Scott's Todo List tutorial in WFA
• Presentation Model - Windows Forms
• White line under menu in Vista