473,466 Members | 1,388 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Need to make a user control transparent

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
7 31094
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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Paul Schnitter | last post by:
Update: My custom control is based on the article "Creating Visual Basic .NET controls from scratch" in "Adventures in .NET" on MSDN. It is designed to be a replacement for the VB6 shape...
1
by: jojo | last post by:
I' d like to develop an active x UserControl, using VB6, with transparent background. The user control will contains an image control. When load GIF image with transparent parts I want that parts ...
1
by: Daimy | last post by:
Can not make a control transparent in XP. Please help me. Thanks! public class Class1 : System.Windows.Forms.CheckBox {
4
by: Efkas | last post by:
Hi, I had some label with BackColor.Transparent and a User Control also with transparent background. When I put a label on the user control, instead to have transparent result I obtain a...
4
by: Nad | last post by:
Hello, I have a user control that has a button and a Calendar. Once you click on the button I display the calendar. Now when I move this user control to a web form, once I click on this button...
0
by: FredC | last post by:
I'm using VS C#.Net 2003. I built a simple windows form app. with the following attributes: - has a BackgroundImage set to a jpeg I built a very simple user control that contains a picture box set...
1
by: FredC | last post by:
I'm using VS 2003, C#.Net 2003. I built a simple windows form app. with the following attributes: - has a BackgroundImage set to a jpeg I built a very simple user control that contains a...
2
by: thi | last post by:
Hi Experts, I am new to C# moving from VB 6.0. Basic i want to know how do i make the label transparent with the control color it currently on. For example I have a picturebox control...
0
by: MasterOfTheDark | last post by:
This one's a hairy one to explain. What I've got is a class called "VistaGroupBox" that I put some nice-looking Vista-style gradients in the background and made to look like the ribbon categories...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.