Need to make a user control transparent

April 29, 2009
zemna@zemna.net
Category:
Tags:

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.

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x
linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram