tags:

views:

944

answers:

2

Does anybody know if it is possible, with windows forms in .net, to change the opacity of a form without it automatically changing the opacity of the controls within the form?

I have a form that is running maximized, that contains a flowlayoutpanel in the centre of the form with controls inside it. I would like to lower the opacity of the form so that the "spare" part around the flowlayoutpanel is partly transparent, but the flowlayoutpanel itself remains solid (im aiming for a lightbox style effect)

A: 

Unfortunately, Opacity is a property of Form not Control. The only way I can imagine this would be possible is if you custom drew the form yourself and used an alpha-component in the brush used to paint the form background. Even then, I don't think it would work as the desktop composition manager (especially relevant on Vista) needs to know how your form is supposed to be composed with the rest of the desktop, and I think the brush would only be transparent against the form background, rather than whatever is underneath it.

Jeff Yates
+2  A: 

Of course, this is possible in WPF by setting the background of the form to transparent (as opposed to setting opacity to 0, which basically sets transparency on both foreground and background).

If you really wanted to, I don't see why you couldn't embed a winforms component into a transparent wpf form, using WindowsFormsHost.

Dave Arkell