Need to make a user control transparent

  • Thread starter Thread starter Chuck
  • Start date Start date
C

Chuck

I am working in C# 2003.
Can anyone tell me how to make a user control transparent. VS help doesn't
help.

What I want to do is draw on a user control during design time and then
place the control on another form. All I want to see is the drawing and I
want anything behind the drawing to show through.

TransparencyKey and Opacity don't compile.

Chuck
 
Opacity only works for top-level windows. If you want translucency at a
control level you will have to paint on to the form directly, using alpha
colors and an imagematrix to draw translucent images.
 
To make your user control transparent, Add code describled 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 usercontrol will be visible.
 
To make your usercontrol transparent place the following code in your
usercontrol class.

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. Just leave blank
}

Step 3:

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

After implementing the above steps, your usercontrol will be transparent.
The controls placed on usercontrols will be visible.
 
To make your usercontrol transparent place the following code in the
usercontrol class

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. Just leave blank
}

Step 3:

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

After implementing the above steps, your user control will be transparent.
The controls placed on usercontrols will be visible.
 
It works! :)
Thanks

Chuck

Shakir Hussain said:
To make your usercontrol transparent place the following code in the
usercontrol class

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. Just leave blank
}

Step 3:

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

After implementing the above steps, your user control will be transparent.
The controls placed on usercontrols will be visible.
 
Back
Top