Need to make a user control transparent

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
 
J

John Wood

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.
 
S

Shakir Hussain

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.
 
S

Shakir Hussain

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.
 
S

Shakir Hussain

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.
 
C

Chuck

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top