I have a label which is on a picture. So I want to make transparent back color of the label. When I make backcolor property of the label to transparent. The picture doesn't showed through the text box back color. The backcolor gets color of the form. Image
Asked
Active
Viewed 3,304 times
0
-
Thats how it works - Transparent means use whatever back color of the parent. There is no concept of one control being "in front of" another one. Please read [ask] and take the [tour] – Ňɏssa Pøngjǣrdenlarp Mar 11 '18 at 14:59
1 Answers
1
The background of a Lable is inherited from its container Background.
You can set a different Parent Container using the [Control].Controls.Add()
method, which sets the Parent property to the new Container (you could also modify the .Parent
property directly).
You can re-define your Label's Parent in the Form constructor (the Public Sub New()
of a Form - insert the code after InitializeComponent()
) or in the Form.Load()
event handler.
Here I'm showing both, pick one:
Public Sub New()
InitializeComponent()
PictureBox1.Controls.Add(Label1)
'Re-define the Label.Location if required
Label1.Location = New Point(0, 0)
End Sub
The same thing in the Form.Load() event:
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
PictureBox1.Controls.Add(Label1)
End Sub
As an alternative, you could use the PictureBox .Paint()
event's e.Graphics
to simply Draw the same Text.
Private Sub PictureBox1_Paint(sender As Object, e As PaintEventArgs) Handles PictureBox1.Paint
Using TextBrush As SolidBrush = New SolidBrush(Me.ForeColor)
e.Graphics.DrawString("BITS Registration ID", Me.Font, TextBrush, New Point(5, 5))
End Using
End Sub

Jimi
- 29,621
- 8
- 43
- 61