Change the shape of the opactity without changing the opacity of the contained controls

Is it possible, with Windows Forms in .NET, to change the opacity of a form without automatically changing the opacity of the controls in the form?

I have a form that works maximized, which contains a flowlayout panel in the center of the form with controls inside it. I would like to reduce the opacity of the form so that the "spare" part around the flowlayout panel is partially transparent, but the flowlayout panel itself remains solid (im tending to lightbox ).

+4
source share
3 answers

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

If you really want to, I don’t understand why you couldn’t embed the winforms component in a transparent wpf form using WindowsFormsHost.

+2
source

Form.TransparencyKey Property

When a color is assigned to the TransparencyKey property, areas of the form that have the same BackColor will display transparently.

If the color assigned to the TransparencyKey property is the same as any form controls, they will also be displayed transparently. For example, if you have a Button control in a form with the TransparencyKey property set to SystemColors.Control, the control will display transparently if the BackColor property of the Button control is not changed to a different color.

+1
source

Unfortunately, Opacity is a property of Form , not Control . The only way I can imagine would be possible if you yourself typed the shape and used the alpha component in the brush used to paint the background of the form.

Even then, I don’t think this will work, since the desktop layout manager (especially relevant in Windows Vista) needs to know how your form should be composed with the rest of the desktop, and I think that the brush only needs to be transparent with respect to the background of the form, not what’s underneath it.

0
source

Source: https://habr.com/ru/post/1277533/


All Articles