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?
You can make a panel or label transparent by specifying the alpha value for the Background color. panel. BackColor = Color.
You may need to restart the code editor after the installation, once the application starts again, you will be able to change the opacity of Visual Studio Code by simply pressing the shortcuts CTRL + ALT + Z to increase the transparency or CTRL + ALT + C to decrease the transparency level.
The Opacity property enables you to specify a level of transparency for the form and its controls. When this property is set to a value less than 100 percent (1.00), the entire form, including borders, is made more transparent. Setting this property to a value of 0 percent (0.00) makes the form completely invisible.
Panel
.ControlStyle.Opaque
for control in constructor using SetStyle
.If true, the control is drawn opaque and the background is not painted.
CreateParams
and set WS_EX_TRANSPARENT
style for it.Specifies that a window created with this style is to be transparent. That is, any windows that are beneath the window are not obscured by the window. A window created with this style receives WM_PAINT messages only after all sibling windows beneath it have been updated.
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 enabled Brush
that is created from BackGroundColor
and Opacity
.Complete Code
public class ExtendedPanel : Panel
{
private const int WS_EX_TRANSPARENT = 0x20;
public ExtendedPanel()
{
SetStyle(ControlStyles.Opaque, true);
}
private int opacity = 50;
[DefaultValue(50)]
public int Opacity
{
get
{
return this.opacity;
}
set
{
if (value < 0 || value > 100)
throw new ArgumentException("value must be between 0 and 100");
this.opacity = value;
}
}
protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.ExStyle = cp.ExStyle | WS_EX_TRANSPARENT;
return cp;
}
}
protected override void OnPaint(PaintEventArgs e)
{
using (var brush = new SolidBrush(Color.FromArgb(this.opacity * 255 / 100, this.BackColor)))
{
e.Graphics.FillRectangle(brush, this.ClientRectangle);
}
base.OnPaint(e);
}
}
Screenshot
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With