BackColor on Transparent controls

B

Brian Smith

I have a custom control derived from ListControl, which does not allow
me to set its BackColor to Transparent (and presumably benefit from
VisualStyles).

How can I determine the true effective BackColor when the control is
hosted on several layers of transparent controls (Panel, TabPage etc),
so that it blends in correctly.

brian
 
G

Guest

Brian,
A control is always tranparent to its parent ,
option one is set background for your custom control as tranparent when you
build the controls it self , when ever you use this it will be tranparent to
its parent , Option two is get the backcolor by <control>.Parent.BackColor
Note: always you need to explicitly mention who is the parent of your
control other wise form is taken as parent by default
Hope this helps
Sudheendra
 
B

Brian Smith

Thanks, but...
If I try to set the BackColor of my control I get the error "Control
does not support transparent background colors" - its not a UserControl,
but derives directly from ListControl.

The problem only occurs when the custom control is hosted within a
UserControl, which does have a transparent background. But the custom
control seems stuck with a fixed color.

The parent control backcolor will thus be returned as Transparent - it
might be several parents up the chain to get an actual color, but I'll
try recursing ands see if that works. I was rather hoping there was a
neat function called something like GetEffectiveBackCColor()!

brian
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top