Transparent background on Picturebox

Antoine

Regular
Joined
Aug 12, 2003
Messages
58
Location
The Netherlands
Dear all,

I have a slight problem. I want to make the background of a picturebox transparent. This because I show icons in this picturebox and there is an image underneath. So in case there is an icon with transparent things in it I want to see the background through it, and not a grey "box". How is this possible ?

When setting the .backcolor = Transparent, it doesn't work. Also during runtime with the .fromargb it doesn't work. Problem is that I need to click on this icon so it needs to be a clickable component.

I also tried to use SetStyle(ControlStyles.SupportsTransparentBackColor, True) but this is also not working. Who can help me please ?

Thanks in advance
Antoine

[edit]
I just found out that when I am doing this with the backgroundimage of a groupbox that this is working properly, but when using this on top of an image from a picturebox it's not., neither on a backgroundimage of a picture box.
 
Last edited:
You need to take the injection! Dump the picturebox and draw the picture yourself. Pictureboxes cannot be transparent unless you modify their region (which is more complicated than drawing the picture yourself)
 
Okay, thank you, but could you give me hint on how to do that ? :confused:

I now used a "panel" and then the backgroundimage, which also works but is not ideal

Thanks in advance !
 
You certainly can draw your own UI, but understanding how transparent controls work in .Net will allow you (usually) to implement transparency effects without writing your own drawing code.

When transparent controls overlap, because of the way that they are drawn, the control on top "cuts a hole" through other controls, showing the underlying form or panel in which they are contained. Therefore, if you want an image to show through a PictureBox with a transparent image, the bottom image must be rendered by .Net as part of the underlying form/panel, meaning that using the BackGroundImage property would be the appropriate mechanism.

Unfortunately, in .Net, when transparent controls are moved around alot, they start to look ugly (try it and you will see what I mean). If your transparent images will just be sitting there then I recommend you do things the way you already are. If there will be alot of re-drawing and moving then you may want to implement your own drawing code, which means hit MSDN. You will need to learn about the Graphics object and Invalided event.
 
This could be completely off of your objective, but if you are just trying to make an image in a picturebox transparent you could do
Visual Basic:
bitmap1.maketransparent = color.black
or if that is not your goal.

Visual Basic:
'pseudo code
dim g as Graphcis
dim mypicture as new bitmap(PathToImage)
mypicture.maketransparent = color.black
g = Me.CreateGraphics

g.drawimage(mypicture,x,y)
 
Back
Top