I have a GIF with a transparent background that I want to put on a form overtop another image. When I do that, the background of the PictureBox control shows up even when I set the BackColor property to Transparent.
Thanks a lot, but I think I need to use a control because the user has to be able to move the images around and then I need to store the final position. This is easy using the different Mouse events but not possible if I draw the image onto the form. Any other suggestions?
I've read about the Forms transparencykey property which sounds like if I set the backcolor of the picturebox to a color (Red) and the transparencykey to the same color then it should make the picturebox backcolor transparent. But this doesn't work for some reason. Any idea why?
yes, that is because the forms transparency key is if you want to make the FORM transparent, for example if you wanted to give the form a non rectangular shape, adobe reader's 6/7 splash screen is a good example of this.
I also know that 2003 had some weird bug with transparency when the PC was on 32bit color instead of 16bit. and you had to use the .MakeTransparent method of the image you were actually trying to make transparent.
Unless someone has a better solution, I think you may have to rethink your strategy. Perhaps you will need to paint the images on the form, and track user mouse movements to move the images via code?
I'm only a visitor in this forum since I don't know .net yet, but if you can make a usercontrol in .net like you can in VB6 then see this thread http://www.vbforums.com/showthread.php?t=385822
you can make user controls, but that doesn't get around the issue of making them transparent to eachother so that you can have them on top of eachother without an overlapping background of the picturebox
If they act the same way as VB6 Usercontrols, then you just set the mask and maskcolor and they will be transparent to each other. In the link I posted above, I wrote some code for someone who wanted to do the same thing.
Private Sub UserControl1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
If Draging = False Then
Draging = True
Xpos = e.X
Ypos = e.Y
End If
End Sub
Private Sub UserControl1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
If Draging = True Then
Me.Left += (e.X - Xpos)
Me.Top += (e.Y - Ypos)
End If
End Sub
Private Sub UserControl1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseUp
Draging = False
End Sub
Private Sub UserControl1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
e.Graphics.DrawImage(myBitMap, 0, 0)
End Sub
End Class
Put it on a form with a picturebox and called it fish
VB Code:
Public Class Form1
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
PictureBox1.Image = Image.FromFile("Backgnd.gif")
Fish.Parent = PictureBox1
End Sub
End Class
You can drag the usercontrol around and see that the picture from the picturebox shows through. It flickers a bit, but maybe there is something that can be done about that.
You can drag the usercontrol around and see that the picture from the picturebox shows through. It flickers a bit, but maybe there is something that can be done about that.
Yeah I was able to get the transparency working, and it looked nice, but the flicker was an issue. I found some sample C# code for drawing a backbuffer that works well, but I am currently working on converting it to VB.NET and integrating it to work with the translucent images
The method I used is supposed to eliminate flicker since I set DoubleBuffer=true
I made a couple of adjustments that reduced flicker even more. Try these:
In the Usercontrol constructor (Sub New) add this line
I can't believe how easy this is after all that work I did trying to do it another way.
There are basically two things you have to do to make a picturebox transparent.
VB Code:
'put it into a container
myPicturebox.Parent = bkgndPictureBox
'set its background color to be transparent
myPictureBox.BackColor = Color.Transparent
Edit: Just noticed that if you have two sprites and they overlap then back sprite does not show through transparent background of front sprite???