Need to make a user control transparent

To make your user control transparent, Add code described in three steps

Step 1
protected override CreateParams CreateParams
{
    get
    {
        CreateParams cp = base.CreateParams;
        cp.ExStyle |= 0x00000020;
        return cp;
    }
}

Step 2
protected override void OnPaintBackground(PaintEventArgs e)
{
    // dont code anything here. Leave blank
}

 

Step 3
protected void InvalidateEx()
{
    if (Parent == null)
        return;
    Rectangle rc = new Rectangle(this.Location, this.Size);
    Parent.Invalidate(rc, true);
}
  

After doing 3 steps, place your user control in the form. Its going to be transparents. The controls placed on user control will be visible.

Leave a Reply