473,396 Members | 1,996 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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 31087
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
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...
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...

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.