473,846 Members | 1,930 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.backcolo r = form1.backcolor
3.) make form1.transpare ncykey = 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.backcolo r = form1.backcolor
3.) make form1.transpare ncykey = 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
TransparencyKe y 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 OnPaintBackgrou nd event and
not drawing anything, but I always get a visible
background.

.

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

"Paul Schnitter" <ps********@luc ent.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.backcolo r = form1.backcolor
3.) make form1.transpare ncykey = 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.backcolo r = form1.backcolor
3.) make form1.transpare ncykey = 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
TransparencyKe y 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 OnPaintBackgrou nd 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.a sp>, 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 TestTrafficeLig h 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(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
TrafficLight1.B ackColor = Me.BackColor
Label1.BackColo r = Me.BackColor
Me.Transparency Key = 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.CreateP arams;
'
cp.ExStyle|=0x0 0000020; //WS_EX_TRANSPARE NT
' return cp;
' }
'}
Get
Dim cp As CreateParams
cp = MyBase.CreatePa rams
cp.ExStyle = cp.ExStyle Or
&H20 'WS_EX_TRANSPAR ENT
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.a sp>, 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 TestTrafficeLig h 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(ByVa l sender As System.Object, ByVal e As System.EventAr gs) Handles MyBase.Load
TrafficLight1.B ackColor = Me.BackColor
Label1.BackColo r = Me.BackColor
Me.Transparency Key = Me.BackColor
End Sub

5. Run and test, I found that the background of both the Label1 and TrafficLight 1 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, OnPaintBackgrou nd, 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/cpconrenderingw indowsformscont rol.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
20189
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 I prefer don't insert a background in MyComponent, and using the MyApp one as general background with MyComponent positionned, but I am not able to have MyComponent background transparent.
8
10614
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 some controls that aren't rectangular and it won't be pretty if I end up with a grey rectangle behind each one. http://msdn.microsoft.com/library/en-us/vbcon/html/vbtskGivingYourControlTransparentBackground.asp?frame=true
5
1514
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) Me.UpdateStyles() Me.BackColor = Color.Transparent Invalidate()
7
629
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 control. My control draws a shape (circle, square, rectangle ...)
4
3878
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 i disable the controls, they all have the standard beige Windows background, is there a way to set the disabled background color too?? Thanks, Ron
2
6590
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 background color. So the image formerly drawn is covered by the latter image with unwanted background color. I wonder if I can get really transparent background color.
8
10184
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 however shows white as the PictureBox moves but I want it to be transparent. The PictureBox BackColor is set to Transparent .. but no affect. I have used PhotoShop to make the image background transparent .. again no affect. If I make the image a...
3
5385
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 Transparent. This so far, works perfect. I now, would like to put another PNG image(an arrow showing positioning on the map) over the last PictureBox. The problem i'm having, the background for this second PictureBox only stays transparent when...
4
3387
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 transparent the background of link label control . LinkLabel lnklbl = new LinkLabel(); lnklbl .Text="Click Me"; lnklbl .BackColor = Color.Transparent; this code not work and background show with white color. please give me idea to transparent...
0
9879
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9725
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10976
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10330
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9477
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5714
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5906
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4521
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 we have to send another system
3
3157
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.