I'm quite a newbie when it comes to coding, but i feel like i have done everything as it should be.

I believe to get a transparent label i need to use the code -

Label1.Parent = PictureBox1
Label1.BackColor = Color.Transparent

I double clicked my picture box and inserted the code, but when i debug the program it still shows a greay background on the label?

Recommended Answers

All 8 Replies

It works for me. What version of vb are you using (I am on vb 2010)? If you added the code after double clicking the picturebox then the code won't execute until you click in the picturebox at run time. Try putting it in the form load handler.

Ahhh now that works. I had to click on the picture box at runtime. When the application is finished, do i have to click every picture when i run the executable? Thanks for the reply.

In the form load event handler just add the code to put the label in the proper container. You can set the transparent property there at run time or in the designer.

I don't think i understand sorry. I double clicked the picturebox1, added the code. Debugged the program. What do i have to do in between? I'm not that familar with coding.

This is what i mean. When i debug the program it shows the labels like this, and the only way to make the text visible is to click on it. How do i make it so the text is visible without having to click it every time?

Thanks

Here's an example. I created a blank form, added a picturebox, then added a label at the centre of the picturebox. Note that even though the label is over the picturebox, it is actually containied in Me.Controls. In the following code, only the line that has the comment "run time" actually has to be in the code. The other three lines set properties that can be set in the designer. This code gets executed when the form loads and does not require that you click on anything.

Public Class Form1    

    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load

        Me.BackColor = Color.Azure             'design time
        PictureBox1.BackColor = Color.Coral    'design time
        Label1.BackColor = Color.Transparent   'design time
        Label1.Parent = PictureBox1            'run time

    End Sub

End Class

Your problem was that when you double clicked on the picturebox in the designer it automatically created a handler for PictureBox1_Click. That is where you added your code and that is why you had to click on the control to execute that code at run time.

Ok, thanks for explaining that to me. I'll have a try later.

Update: Just tried it and it works perfectly. Appreciate you explaining it to me.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.