Label BackColor Transparent?

solfinker

Well-known member
Joined
Aug 6, 2013
Messages
71
Programming Experience
Beginner
Sorry about the low level of my question, but I have no clue.
I have set the backcolor of my labels to Transparent, thus the label's backcolor takes the color of the form. So far so good.
Now I want to change the skin and the easiest way is to turn several Pictureboxes' visible property from False to True and viceversa.
But the backcolor of my labels continues taking the color of the form, not the one of the Picturebox behind it.
The same happens to a Chart with Backcolor = Transparent
Is there an easy way to fix this?

Thanks a lot for your help.
 
Last edited:
When it's BackColor is set to Transparent, a control will display the contents of its Parent behind it, even if there is another control in between. If you want a PictureBox to show through a Label or some other control then the easiest way is to make that PictureBox the Parent of that control. That cannot be done in the designer but is fairly simple to achieve in code. If you place a PictureBox and a Label on a form with the Label positioned in front of the PictureBox in the exact location you want it to appear to the user, this code will re-parent the Label without changing its relative location:
Me.Label1.Location = Me.PictureBox1.PointToClient(Me.Label1.PointToScreen(Point.Empty))
Me.Label1.Parent = Me.PictureBox1
You'd probably want to put that code in the Load event handler of the form.
 
I have the same problem with OvalShape and RectangularShape.
VB tells me:
Kind of value 'System.Windows.Forms.PictureBox' cannot convert into 'Microsoft.VisualBasic.PowerPacks.ShapeContainer'
on Form8.os11.Parent = Form8.PictureBox1
 
Those shapes are special components that is not themselves controls, when you add one to form the designer also adds an invisible ShapeContainer control that acts as its container, and is where these shapes are drawn onto. Additional shapes will be added to same ShapeContainer (you can see this in Document Outline window).
If you want to bring the shapes to front, for example to partially overlay a PictureBox, then you may call ShapeContainer.BringToFront method in code, for example from Load event handler. The default ShapeContainer is exposed by a member variable and named ShapeContainer1 (how surprising :surprise:), so code will simply be:
ShapeContainer1.BringToFront()

A ShapeContainer can be parented to another control, but that is not necessary and will not intuitively produce the effect you seek. This is because this special container will take the entire size of the form, also when form is resized.
 
Great, but more one comment. Since you first said you were trying to parent the shape to a PictureBox you are probably containing them fully within the control, so an alternative to using shapes components is to use the Paint event to draw the shapes. For example use the Graphics class methods DrawEllipse or DrawLine. The Graphics object is given by Paint event parameter e.Graphics.
 
I am making a kind of cardiograph with the time on the X axis.
Now I have the points - the rectangle and oval shapes - and I may add the lines joining them: that is the moment to do some painting using the DrawLine.
I hope I know how.
Thank you very much for your suggestion
 
Back
Top