I'm creating a simple form with WinForms with dotNET7 using VS2022:
The gray rectangle is a Panel, which I need to make transparent. You can see a label underneath the panel, and I wish it to be visible, while the panel itself is brought to front.
With dotNET framework, it was so easy:
public class TransparentPanel : Panel
{
protected override CreateParams CreateParams
{
get
{
var cp = base.CreateParams;
cp.ExStyle |= 0x00000020; //WS_EX_TRANSPARENT
return cp;
}
}
protected override void OnPaintBackground(PaintEventArgs e)
{
//base.OnPaintBackground(e);
}
}
However, with dotNET7 and VS2022 (don't really know which one causes the limitation), when I change the Panel to "TransparentPanel", designer simply gets rid of it:
With original panel, these are my components:
After changing panel1 from System.Windows.Forms.Panel
to TransparentPanel
:
I tried changing panel's background to transparent, but it's not the giving me my required results:
this.panel1.BackColor = System.Drawing.Color.Transparent;
Also tried to apply color with alpha:
this.panel1.BackColor = Color.FromArgb(100, Color.Red);
So how can I achieve this very simple thing with dotNET7?