473,396 Members | 2,108 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.

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 9450
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: 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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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
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...

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.