By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,702 Members | 1,726 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,702 IT Pros & Developers. It's quick & easy.

Need to make a user control transparent

P: n/a
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
Nov 16 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
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.

--
John Wood
EMail: first name, dot, last name, at priorganize.com
"Chuck" <ce*****@austin.rr.com> wrote in message
news:hF*****************@fe1.texas.rr.com...
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

Nov 16 '05 #2

P: n/a
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.

--
Shak
(Houston)
"Chuck" <ce*****@austin.rr.com> wrote in message
news:hF*****************@fe1.texas.rr.com...
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

Nov 16 '05 #3

P: n/a
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.

--
Shak
(Houston)
"Chuck" <ce*****@austin.rr.com> wrote in message
news:hF*****************@fe1.texas.rr.com...
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

Nov 16 '05 #4

P: n/a
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.

--
Shak
(Houston)
"Chuck" <ce*****@austin.rr.com> wrote in message
news:hF*****************@fe1.texas.rr.com...
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

Nov 16 '05 #5

P: n/a
It works! :)
Thanks

Chuck

"Shakir Hussain" <sh**@fakedomain.com> wrote in message
news:Oy**************@tk2msftngp13.phx.gbl...
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.

--
Shak
(Houston)
"Chuck" <ce*****@austin.rr.com> wrote in message
news:hF*****************@fe1.texas.rr.com...
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


Nov 16 '05 #6

P: n/a
Hi Shak,

I am a new Visual Basic programmer. Do you know how the below code can be
used in Visual Basic .Net. I have converted the first two steps. But the
third step does seem to work for me.

Thanks for your help.

Loc

"Shakir Hussain" wrote:
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.

--
Shak
(Houston)
"Chuck" <ce*****@austin.rr.com> wrote in message
news:hF*****************@fe1.texas.rr.com...
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


Nov 16 '05 #7

P: n/a
Out of interest

would Step 2 be the same as setting

this.SetStyle(ControlStyle.AllPaintinWmPaint, true); ?

and Step 3

How is this different from calling

this.Invalidate(); // note no params

Regards

Richard Blewett - DevelopMentor
http://staff.develop.com/richardb/weblog

nntp://news.microsoft.com/microsoft.public.dotnet.languages.csharp/<81**********************************@microsoft.co m>

Hi Shak,

I am a new Visual Basic programmer. Do you know how the below code can be
used in Visual Basic .Net. I have converted the first two steps. But the
third step does seem to work for me.

Thanks for your help.

Loc

"Shakir Hussain" wrote:
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.

--
Shak
(Houston)
"Chuck" <ceat

Nov 16 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.