|
-
June 14th, 2007, 11:53 PM
#1
PictureBox Transparent
Hi. I have a picturebox control with an image that is a GIF. The image is not an animation, only a single frame. The background of the image is transparent, as i erased it in photo shop. What code can i use to make the rest of the picturebox transparent, so there isnt a box around my circular GIF object? I want a result like in visual basic 6.0 with an image control. is there an image control for vb.net?
Last edited by TCanuck42; June 15th, 2007 at 12:31 AM.
-
June 15th, 2007, 07:18 PM
#2
Re: PictureBox Transparent
If you look under the properties for the picturebox, choose "BackColor" the first choice under "Web" is Transparent. Try that.
- Joe
-
June 15th, 2007, 11:32 PM
#3
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?
-
June 18th, 2007, 12:55 AM
#4
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.
Good Luck,
Craig - CRG IT Solutions - Microsoft Gold Partner
-My posts after 08/2015 = .NET 4.x and Visual Studio 2015
-My posts after 11/2011 = .NET 4.x and Visual Studio 2012
-My posts after 02/2010 = .NET 4.0 and Visual Studio 2010
-My posts after 12/2007 = .NET 3.5 and Visual Studio 2008
-My posts after 04/2007 = .NET 3.0 and Visual Studio 2005
-My posts before 04/2007 = .NET 1.1/2.0
*I do not follow all threads, so if you have a secondary question, message me.
-
June 19th, 2007, 05:15 AM
#5
Re: PictureBox Transparent
TCanuck : What do you mean by :
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 :
Last edited by HanneSThEGreaT; June 14th, 2010 at 05:40 AM.
-
June 23rd, 2007, 01:19 PM
#6
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?
-
June 23rd, 2007, 02:25 PM
#7
Re: PictureBox Transparent
Have a look here, it explains why the flickering occur :
http://www.codeguru.com/forum/showpo...45&postcount=4
-
June 23rd, 2007, 02:39 PM
#8
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!
-
June 25th, 2007, 06:33 AM
#9
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)
-
June 25th, 2007, 04:53 PM
#10
Re: PictureBox Transparent
Sorry, but i haven't worked much with constructors and destructors. please explain. thanks in advance
Last edited by TCanuck42; June 25th, 2007 at 05:22 PM.
-
June 26th, 2007, 12:43 AM
#11
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
-
June 26th, 2007, 04:31 PM
#12
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?
-
June 26th, 2007, 04:35 PM
#13
Re: PictureBox Transparent
Hmm...
Could you perhaps attach your project ¿
-
June 26th, 2007, 05:32 PM
#14
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
-
June 27th, 2007, 12:45 AM
#15
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|