Re: PictureBox Transparent
If you look under the properties for the picturebox, choose "BackColor" the first choice under "Web" is Transparent. Try that.
- Joe
Re: PictureBox Transparent
Thanks but that doesnt work. What that does is colour the back of the picturebox to match that of the form. If i have many picture boxes on the screen to create a larger image, there is still a rectangle surrounding the main image. The image itself has a transparent background, so what i am seeing is the picturebox's background. How can the picturebox's background, not the actual images, be transparent? Are there any controls i can download?
Re: PictureBox Transparent
The best way to do this is to simply draw the image directly over the form by overriding the OnPaint event:
Code:
Public Class Form1
Private _myImage As New Bitmap("C:\myImage.gif")
Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
MyBase.OnPaint(e)
e.Graphics.DrawImageUnscaled(New Bitmap(_myImage), 100, 100)
End Sub
End Class
You can get a lot more creative, but that's the idea.
Re: PictureBox Transparent
TCanuck : What do you mean by :
Quote:
there is still a rectangle surrounding the main image
¿
This is perhaps a dumb comment / question from my side, but Did you perhaps set the Picturebox's BorderStyle to something different than None
Because, no matter how I try, I cannot replicate the same behaviour you've found.
I made 2 GIFs, both with Transparent Backgrounds. I added 2 Pictureboxes to my form, then, in each Picturebox, added each respective picture. With one Picturebox ( The Arrow ), I set the BorderStyle to None.
With the second Picturebox ( The Doughnut ), I set the BorderStyle to FixedSingle
I did not add any code.
And this is what I got at run time :
Re: PictureBox Transparent
I have a gradient set as the background to an picturebox. I meant that regardless of whether or not the GIF is transparent or not, their is still a solid colored rectangle surrounding the image. You can see what i mean if you set a picture to a picturebox behind the arrow and then set the arrows backcolor to transparent.
I did, however, discover that if you execute the following code, the "arrow" in you example will be transparent to the picturebox behind it.
Code:
picArrow.Parent = PictureBox
Now, when there is code that moves the arrow's top and left attributes, there is a slight flickering/blinking effect. How can this be removed?
Re: PictureBox Transparent
Have a look here, it explains why the flickering occur :
http://www.codeguru.com/forum/showpo...45&postcount=4
Re: PictureBox Transparent
Thanks for the reply. All three options sound good. Could you please explain just how i could execute option 1, and if that doesn't work, option 2? Thanks in advance!
Re: PictureBox Transparent
For method 1, Try putting this in your Constructor :
Code:
SetStyle(ControlStyles.DoubleBuffer, True)
SetStyle(ControlStyles.UserPaint, True)
SetStyle(ControlStyles.AllPaintingInWmPaint, True)
Re: PictureBox Transparent
Sorry, but i haven't worked much with constructors and destructors. please explain. thanks in advance
Re: PictureBox Transparent
OK, try this :
Code:
Public Sub New()
MyBase.New()
SetStyle(ControlStyles.DoubleBuffer, True)
SetStyle(ControlStyles.UserPaint, True)
SetStyle(ControlStyles.AllPaintingInWmPaint, True)
End Sub
Re: PictureBox Transparent
Thanks for the prompt reply. I added that code to my Form and ran the program and there was an error. It said it was missing the "InitializeComponent" command so i added it in and then there were no more errors, but the flickering still occurred. Should i have done something else, or so i need to call the sub somewhere?
Re: PictureBox Transparent
Hmm...
Could you perhaps attach your project ¿
Re: PictureBox Transparent
My project is very large, so i will create a sample of what i'm using and what is happening. As you walk around in the demo I made (its like a game), you'll notice once you go over objects or you are walking against a collision detector, there is a lot of flickering. Hope this helps!
By the way, even the small portion sample i created exceeds the codeguru 2mb limit, even while zipped, so please download it at this link: http://rapidshare.com/files/39539835...oblem.rar.html
Re: PictureBox Transparent
The only reason I can see why the zip may be so big is because of the EXE files included in it, is that so ¿
Just remove the EXE files, and see if you can upload it then :)