Hierarchy & Transparent Controls
-
I'm working on a game API which uses potentially transparent controls for basic layering effects (I don't want anything too fancy just yet). My first problem was enabling transparency, but that was easily solved using SetStyle(). Unfortunately, when I then tried placing a transparent layer over another layer, it shows the form's background color (here, black) through the transparency, instead of the layer beneath. I was finally able to get the proper effect by making the top-layer control a child of the bottom-layer control, but doing it that way makes some other effects nigh impossible. Is there a way to get transparent controls to display the other controls beneath them? Any help is appreciated.
A little learning is a dangerous thing; Drink deep, or taste not, the Pierian Spring. —Alexander Pope
-
I'm working on a game API which uses potentially transparent controls for basic layering effects (I don't want anything too fancy just yet). My first problem was enabling transparency, but that was easily solved using SetStyle(). Unfortunately, when I then tried placing a transparent layer over another layer, it shows the form's background color (here, black) through the transparency, instead of the layer beneath. I was finally able to get the proper effect by making the top-layer control a child of the bottom-layer control, but doing it that way makes some other effects nigh impossible. Is there a way to get transparent controls to display the other controls beneath them? Any help is appreciated.
A little learning is a dangerous thing; Drink deep, or taste not, the Pierian Spring. —Alexander Pope
I would advise you to create you own class for layered effects. Its not as hard as it sounds! My method for creating your app would be to draw all my layers from my custom classes.
-
I'm working on a game API which uses potentially transparent controls for basic layering effects (I don't want anything too fancy just yet). My first problem was enabling transparency, but that was easily solved using SetStyle(). Unfortunately, when I then tried placing a transparent layer over another layer, it shows the form's background color (here, black) through the transparency, instead of the layer beneath. I was finally able to get the proper effect by making the top-layer control a child of the bottom-layer control, but doing it that way makes some other effects nigh impossible. Is there a way to get transparent controls to display the other controls beneath them? Any help is appreciated.
A little learning is a dangerous thing; Drink deep, or taste not, the Pierian Spring. —Alexander Pope
CompMan44 wrote:
Unfortunately, when I then tried placing a transparent layer over another layer, it shows the form's background color (here, black) through the transparency, instead of the layer beneath.
This is exactly what it's supposed to do. The color Transparent is anything but. Transparent tells the control's background properties to match those of the parent container. It does NOT make the control Transparent. As you've found out, control-over-control transparency doesn't work the way the term "Transparent" would lead you to believe. The way around this is to not use controls to draw your graphics. Instead, you should be drawing your graphics to an off-screen buffer and "flip pages" between what's being drawn on and what the user sees, or use DirectX, where you'll have FAR more control over your graphics.
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007 -
CompMan44 wrote:
Unfortunately, when I then tried placing a transparent layer over another layer, it shows the form's background color (here, black) through the transparency, instead of the layer beneath.
This is exactly what it's supposed to do. The color Transparent is anything but. Transparent tells the control's background properties to match those of the parent container. It does NOT make the control Transparent. As you've found out, control-over-control transparency doesn't work the way the term "Transparent" would lead you to believe. The way around this is to not use controls to draw your graphics. Instead, you should be drawing your graphics to an off-screen buffer and "flip pages" between what's being drawn on and what the user sees, or use DirectX, where you'll have FAR more control over your graphics.
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007Dave Kreskowiak wrote:
Transparent tells the control's background properties to match those of the parent container. It does NOT make the control Transparent.
I was afraid of that. Actually, I'm using a custom OnPaint handler, so I guess
FillRectangle()
et al. is where that "feature" lies? Thanks for your suggestions. I'd rather not get into DirectX just yet, but if that's what it takes.... P.S. Are there ANY functions (preferably GDI) that handle transparent and semi-transparent colors properly?A little learning is a dangerous thing; Drink deep, or taste not, the Pierian Spring. —Alexander Pope
-
Dave Kreskowiak wrote:
Transparent tells the control's background properties to match those of the parent container. It does NOT make the control Transparent.
I was afraid of that. Actually, I'm using a custom OnPaint handler, so I guess
FillRectangle()
et al. is where that "feature" lies? Thanks for your suggestions. I'd rather not get into DirectX just yet, but if that's what it takes.... P.S. Are there ANY functions (preferably GDI) that handle transparent and semi-transparent colors properly?A little learning is a dangerous thing; Drink deep, or taste not, the Pierian Spring. —Alexander Pope
Since Windows Forms is based on GDI+, no, there isn't.
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007