Antoine Posted September 26, 2005 Posted September 26, 2005 (edited) 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. Edited September 26, 2005 by Antoine Quote
Leaders Iceplug Posted September 26, 2005 Leaders Posted September 26, 2005 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) Quote Iceplug, USN One of my coworkers thinks that I believe that drawing bullets is the most efficient way of drawing bullets. Whatever!!! :-(
Antoine Posted September 26, 2005 Author Posted September 26, 2005 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 ! Quote
Leaders snarfblam Posted September 27, 2005 Leaders Posted September 27, 2005 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. Quote [sIGPIC]e[/sIGPIC]
Nate Bross Posted September 28, 2005 Posted September 28, 2005 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 bitmap1.maketransparent = color.black or if that is not your goal. 'pseudo code dim g as Graphcis dim mypicture as new bitmap(PathToImage) mypicture.maketransparent = color.black g = Me.CreateGraphics g.drawimage(mypicture,x,y) Quote ~Nate� ___________________________________________ Please use the [vb]/[cs] tags on posted code. Please post solutions you find somewhere else. Follow me on Twitter here.
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.