I recently started exploring Visual Studio.
I was trying to create a slide menu. More specifically, when the user would press the button a submenu would pop up to the right. To achieve that i have placed a Panel
to resize itself. Apart from functionality i wanted to add a bit more design and make the Panel
appear a bit faded.
I know that Panels
in Visual studio do not have opacity, but i was thinking if anyone knows a way-trick-idea about how it can be achieved. I tried a Picture Box
but that too didn't have Opacity as a property. I avoided to use the regular Menu
object that visual studio offers because i wanted to add more design. Any ideas?
Panel
.ControlStyle.Opaque
for control in constructor usingSetStyle
.CreateParams
and setWS_EX_TRANSPARENT
style for it.Opacity
property that accepts values from 0 to 100 that will be used as alpha channel of background.OnPaint
and fill the background using an alpha enabledBrush
that is created fromBackGroundColor
andOpacity
.Complete Code
Screenshot
To make a control "transparent", you should paint the right area of its parent onto the control. That's what the
Button
does before it draws its content so the rounded corners will be transparent.To mimic semi-transparency, you can paint the form onto the panel, and then draw something with Alpha:
Please note that the
ButtonRenderer.DrawParentBackground
does not paint the controls of the form, which overlap with the panel, but only the background of the form.