473,325 Members | 2,771 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,325 software developers and data experts.

How do I make the background of a control transparent?

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

My control draws a shape (circle, square, rectangle ...)
on the background. If

1.) put a MyShapeControl on the form
2.) make shape1.backcolor = form1.backcolor
3.) make form1.transparencykey = form1.backcolor
4.) put a backgoundimage on the form

You can see right through
the background of my control to whatever is behind the
form. Also click events, dragdrops, etc. are transfered
to whatever is below the form.

That is NOT the same behavior as the stock .NET controls,
contrary to the documentation. If I

1.) put a label control on the form
2.) make label1.backcolor = form1.backcolor
3.) make form1.transparencykey = form1.backcolor
4.) put a backgoundimage on the form

the label control background is not transparent.

I don't understand why they changed the VB6 behavior or
why they think this new behavior is good.

All I want is a shape control who's background is
transparent to the other controls on my form. How do I do
that?
-----Original Message-----
The System.Windows.Forms.Form class has a TransparencyKey
property that sets a specific background color to be
transparent.

The System.Windows.Forms.Control class does not have that
property. How do I add the functionality of the
TransparencyKey property to a Control?

Unless I am missing something, it seems that all .NET
controls are missing a very important property by not
allowing them to have a transparent background.

I have tried overriding the OnPaintBackground event and
not drawing anything, but I always get a visible
background.

.

Jul 19 '05 #1
5 9440
You need to set the controls Region() for the implementation you are after.
The label is a problem though.

"Paul Schnitter" <ps********@lucent.com> wrote in message
news:13****************************@phx.gbl...
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
control.

My control draws a shape (circle, square, rectangle ...)
on the background. If

1.) put a MyShapeControl on the form
2.) make shape1.backcolor = form1.backcolor
3.) make form1.transparencykey = form1.backcolor
4.) put a backgoundimage on the form

You can see right through
the background of my control to whatever is behind the
form. Also click events, dragdrops, etc. are transfered
to whatever is below the form.

That is NOT the same behavior as the stock .NET controls,
contrary to the documentation. If I

1.) put a label control on the form
2.) make label1.backcolor = form1.backcolor
3.) make form1.transparencykey = form1.backcolor
4.) put a backgoundimage on the form

the label control background is not transparent.

I don't understand why they changed the VB6 behavior or
why they think this new behavior is good.

All I want is a shape control who's background is
transparent to the other controls on my form. How do I do
that?
-----Original Message-----
The System.Windows.Forms.Form class has a TransparencyKey
property that sets a specific background color to be
transparent.

The System.Windows.Forms.Control class does not have that
property. How do I add the functionality of the
TransparencyKey property to a Control?

Unless I am missing something, it seems that all .NET
controls are missing a very important property by not
allowing them to have a transparent background.

I have tried overriding the OnPaintBackground event and
not drawing anything, but I always get a visible
background.

.

Jul 19 '05 #2
Hello Paul,

I checked the TrafficLight control contains in the article "Creating Visual
Basic .NET Controls from Scratch"
<http://msdn.microsoft.com/library/de...-us/dnadvnet/h
tml/vbnet08142002.asp>, and found that it has the same behavior with the
.NET stock controls say, Label control. The following is what I did:

1. Open the TestTrafficeLigh project.

2. Add a Label control in Form1.

3. Point BackgroupImage of From1 to a jpg file.

4. Add the following code:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
TrafficLight1.BackColor = Me.BackColor
Label1.BackColor = Me.BackColor
Me.TransparencyKey = Me.BackColor
End Sub

5. Run and test, I found that the background of both the Label1 and
TrafficLight1 are transparent.

Would you please check it on your side. I look forward to your response.

Have a nice day!

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! ¨C www.microsoft.com/security
This posting is provided ¡°as is¡± with no warranties and confers no rights.

Jul 19 '05 #3
Thanks for responding,

I did what you requested. The TrafficLight background is
now totally transparent. That is, transparent right
through the form. Whatever is behind the form shows
through. The procedure had no effect on the label. The
label's backgound was opaque with the background color =
the forms's transparencykey color.

That is not the results I want anyway. What I want is a
Shape control like the one that exists in VB6. The
background is transparent with respect to whatever is
below it in the Z-order, on the same form.

I have found the beginning's of a solution on
http://www.bobpowell.net/transcontrols.htm. I had to
translate from C++ or C#.

Protected Overrides ReadOnly Property
CreateParams() As CreateParams
' From:
http://www.bobpowell.net/transcontrols.htm
'protected override CreateParams
CreateParams
'{
' get
' {
' CreateParams cp=base.CreateParams;
'
cp.ExStyle|=0x00000020; //WS_EX_TRANSPARENT
' return cp;
' }
'}
Get
Dim cp As CreateParams
cp = MyBase.CreateParams
cp.ExStyle = cp.ExStyle Or
&H20 'WS_EX_TRANSPARENT
Return cp
End Get
End Property
This gives the the background i want. However I have a
problem when the shape moves or resizes. The background
doesn't always repaint properly, especially when two shape
controls ovelap.

- Paul
-----Original Message-----
Hello Paul,

I checked the TrafficLight control contains in the article "Creating Visual Basic .NET Controls from Scratch"
<http://msdn.microsoft.com/library/default.asp? url=/library/en-us/dnadvnet/html/vbnet08142002.asp>, and found that it has the same behavior with the .NET stock controls say, Label control. The following is what I did:
1. Open the TestTrafficeLigh project.

2. Add a Label control in Form1.

3. Point BackgroupImage of From1 to a jpg file.

4. Add the following code:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
TrafficLight1.BackColor = Me.BackColor
Label1.BackColor = Me.BackColor
Me.TransparencyKey = Me.BackColor
End Sub

5. Run and test, I found that the background of both the Label1 and TrafficLight1 are transparent.

Would you please check it on your side. I look forward to your response.
Have a nice day!

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! ¨C www.microsoft.com/security
This posting is provided ¡°as is¡± with no warranties and confers no rights.
.

Jul 21 '05 #4
Hi Paul,

Thanks for your update. I am checking this issue and will update you with
my informatoin.

Have a nice day!

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! ¨C www.microsoft.com/security
This posting is provided ¡°as is¡± with no warranties and confers no rights.
Jul 21 '05 #5
Hi Paul,

It seems to me that the problem you are facing is concerning repaint. Did
you handle the OnPaint, OnPaintBackground, and OnResize events? I believe
the following MSDN article is helpful:

Rendering a Windows Forms Control
http://msdn.microsoft.com/library/de...us/cpguide/htm
l/cpconrenderingwindowsformscontrol.asp

Hope this helps.

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! ¨C www.microsoft.com/security
This posting is provided ¡°as is¡± with no warranties and confers no rights.
Jul 21 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Efkas | last post by:
My application have some level : 1. MyButton class with Label inheritance 2. MyComponent as User Control loading and positionning some of MyButtons 3. MyApp loading and positionning MyComponent ...
8
by: Grahammer | last post by:
Is it possible to set the background of a usercontrol as transparent? I tried setting the background image of the usercontrol to a transparent GIF, but that caused MAJOR problems. I'm making...
5
by: Juan Romero | last post by:
Hey guys, Does anyoone know how to make a control with transparent background? This is what I have so far and it doesn't work: Me.SetStyle(ControlStyles.SupportsTransparentBackColor, True)...
7
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...
4
by: RSH | last post by:
This might be a dumb question but I have searched everywhere...I have a form which uses a custom background color. I have set the control's backgrounds to transparent, which works great. But when...
2
by: Niu Kun | last post by:
Dear all, I'm trying to draw many overlapped PNG files with transparent background in imagebox control. But the transparent background in this control is rendered as the main control's...
8
by: Brian Ward | last post by:
I am looking for a simple way to set the image transparency in a PictureBox. I have a moving PictureBox containing a graphic image .. moving by incrementing its Left property. The background...
3
by: kirk | last post by:
I have a form with a PictureBox control on it. The .Image property is set to a PNG file(which shows the picture of the US map) with some transparency in it. The .BackColor property is set to...
4
by: Rishabh Indianic | last post by:
i am developing smart phone application with VS 2005 using C#. i am trying to transparent the background of link label control which dynamically added in panel. i try with following code to...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.