Chcę uzyskać UserControl z przezroczystym tłem, wszystko działa pięknie, jednak kiedy zmienię DoubleBuffer na true tło nie jest już przezroczyste, nie mam pojęcia co z tym zrobić ponieważ potrzebuje DoubleBuffer.
Tutaj uproszczony kod mojej kontrolki:
public partial class UserControl1 : UserControl
{
public UserControl1()
{
InitializeComponent();
this.SetStyle(ControlStyles.DoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint, true);
}
protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.ExStyle |= 0x00000020;//WS_EX_TRANSPARENT
return cp;
}
}
private int opacity;
public int Opacity
{
get { return opacity; }
set
{
opacity = value;
this.InvalidateEx();
}
}
protected override void OnPaintBackground(PaintEventArgs e)
{
Color bk = Color.FromArgb(Opacity, this.BackColor);
e.Graphics.FillRectangle(new SolidBrush(bk), e.ClipRectangle);
}
protected void InvalidateEx()
{
if (Parent == null)
return;
Rectangle rc = new Rectangle(this.Location, this.Size);
Parent.Invalidate(rc, true);
}
}