When i run my code, the picture box has a background colour, even though I have set the background colour to transparent in the properties window. any ideas?
Asked
Active
Viewed 3,652 times
1 Answers
3
I assume you're overlapping a PictureBox
over some other control and expecting to see through the PictureBox
. That's not how it works - controls with transparent backgrounds are only transparent relative to their parent, not other controls. You could draw them using GDI+ by overriding the OnPaint
method of your form:
Private Shared ReadOnly SomeImage As Image = My.Resources.blah 'Get your image somewhere
Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
Dim g As Graphics = e.Graphics
g.DrawImage(SomeImage, xCoordinate, yCoordinate)
'Draw as many images or text as you want.
End Sub
Also, it seems that people are mostly looking for this functionality to make a game. Are you making a game? Please learn graphics before making a game if this is the case. There are many good tutorials out there.

Ry-
- 218,210
- 55
- 464
- 476
-
Thanks. I'm not making a game, I'm trying to practice a* path-finding for AS3, but am more comfortable in VB. – Sam Feb 18 '12 at 15:08
-
Although now i have a new problem - the line i'm drawing doesn't show up over the controls i have on the form. Is it drawn before them? – Sam Feb 18 '12 at 15:16
-
1@Sam: Yes, it is. To do that, you need to draw them *all* using GDI. But don't worry - it's great because you don't need pictures. (See `Graphics.DrawLine`!) – Ry- Feb 18 '12 at 15:17
-
awesome, thanks - I didn't know you could do this! I have done a lot of XNA in the past, so this should sort it out. thanks for the quick reply. – Sam Feb 18 '12 at 15:22
-
Thanks. But is there another way? I want to create a transparent picturebox as a "layer". – Jet Jul 24 '13 at 17:13
-
@Jet: Not in Windows Forms… but GDI+ isn’t that bad :) – Ry- Jul 24 '13 at 17:13