Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Windows.Forms.Label Transparent Background

Status
Not open for further replies.

IjumpOverU

Technical User
Jul 31, 2003
43
US
I think I'm just dumb and I have searched other threads about this topic. I cannot for the life of me figure out if and how to get the background of a standard Windows.Forms.Label to be transparent. I looked up the MSDN article but that seems to be only for a form or a user created label class. Is there any way to make the normal label.backcolor transparent?

Thanks!!
 
Select the Web Tab in the pop-up for BackColor in the PropertyGrid, top item is Transparent
 
I've just noticed your previous posts on this and you say that neither of the above solutions works. I've tried both methods and I can not find a problem, but as a workaround, you could try Label1.BackColor = Me.BackColor. This works for me, so hopefully it will work for you.
 
I certainly believe that it works for you but for whatever reason it does not for me. I tried all of your suggetions and none did what I expect.

Maybe I am thinking about this the wrong way. I have a picture box and a label on top of it. When I set the background color to transparent I would expect to see the text of the label on the image in the picture box. Instead I see I grey background for the label on top of the picture box. I have used a screen repaint to make this work but it is a headache when trying to position it and managind the gui.
 
How did you do the screen repaint. I'm trying to do the same thing. Thanks.
 
If setting the label to transparent isn't working then check to see if you have the FlatStyle property to Standard (it doesn't work if it is set to System).

--------------------------------------------------------------------------------------------------------------------------------------------

Need help finding an answer?

Try the search facility ( or read FAQ222-2244 on how to get better results.
 
Even with the FlatStyle set to Standard, the problem we're addressing still occurs. I've read it's because the label doesn't actually become transparent, but just copies the portion of the form it's on. Because it's copying the form itself, a picturebox behind the label isn't shown.
 
Your best bet is probrably going to be to use a graphics object to draw a string. It's an easy way to display text with out having to worry about the issues with transparent back grounds.

Code:
Dim myBrush As New SolidBrush(Color.Black)
Dim f As Font = New Font(Font.Bold, 20)
Me.CreateGraphics.DrawString([b]StringToDraw[/b], f, myBrush, [b]X_Coordinate[/b], [b]Y_Coordinate[/b])

-Rick, who is dreaming of the days of Avalon.

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
Rick, how do I get that text to display on top of my picturebox?
 
Jon
Just create a graphics handler for your picturebox control first
Code:
dim g as Graphgics
g = Me.xPicture.CreateGraphics()
Dim myBrush As New SolidBrush(Color.Black)
Dim f As Font = New Font(Font.Bold, 20)
g.DrawString(StringToDraw, f, myBrush, X_Coordinate, Y_Coordinate)


Sweep
...if it works dont mess with it
 
Sweep, your response solves IjumpOverU's problem, but not mine. I'll explain my problem. I have a screen saver with an image that just bounces around the screen. You know the kind; the picture moves slowly to the bottom right of the screen and when it hits an edge it bounces in the other direction. I want text in the center of the screen to show up above my picture as it passes underneath. Any ideas? Thanks.
 
Rick, again, how do I use DrawString to draw on top of my picturebox? I have a picturebox, and a timer on my control, with the timer.Interval set to 1. Inside timer.Tick I check to see where the picturebox is, and which diagonal direction it's moving. If it hasn't hit the edge of the screen I just increment it's top and left properties, depending on which way it's moving. When I use DrawString, the pictureBox moves over top of the string. I want it under my string. Thanks.
 
I do have it in the timer.Tick event to redraw every time the picturebox moves, but it's still displaying underneath my picturebox. Even if I take the timer away, leave the picturebox in the center of the screen, and use g.DrawString in the form.Paint event, it's still underneath the picturebox.
 
Rick, I'm looking at what I explained before, not believing that even when I was trying to better explain what I wanted to do I didn't do a good job. I want the string to remain in one place on the form, while the picturebox moves. So the string sits in the center of the screen while the picturebox bounces around. Whenever the picturebox overlaps with the string, the string is seen on top. Sorry for the confusion.
 
Imagine the Form is a peice of paper.

Now imagine the Image box as another piece of paper.

Write the words "Hello World" in the middle of the form paper.

Move the image box paper over the middle of the form paper.

This is why painting the string on the form will not work.
However, If you paint the string on the form, AND paint the string on the image box (when it's in the middle area) and off set the string in the image box so that it always get's painted over the string on the form. You can create the illusion that the string is over everything.

Another option would be double buffering. Create a bitmap object the size of the form, draw the image from the image box on it at the location you want, then draw the string on top of it. Then draw the Bitmap onto the form. This is called double buffering because you draw the complete image off of the screen, then draw the entire image at once on the screen. It eliminates many of these problems with layers and flickering.

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top