Milkus1
asked on
Can i get true transparency with pictureboxes?
I have an app that places pictureboxes onto another larger picturebox.
My transparent gifs take on the backcolor of the larger picturebox.
Problem is when the smaller ones overlap, i dont get 'true' transparency...meaning the small picturebox below doesnt show thru...is it possible??
My transparent gifs take on the backcolor of the larger picturebox.
Problem is when the smaller ones overlap, i dont get 'true' transparency...meaning the small picturebox below doesnt show thru...is it possible??
HMMMM, I was wrong you CAN get it also with 2 pictureboxes
Private Sub Form14_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim x As New PictureBox
x.BackColor = Color.Transparent
x.SizeMode = PictureBoxSizeMode.AutoSiz e
Dim Y As Image
Y = Image.FromFile("c:\yoursec ondtranspa rentimage. gif")
x.Image = Y
PictureBox1.Controls.Add(x )
End Sub
Private Sub Form14_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim x As New PictureBox
x.BackColor = Color.Transparent
x.SizeMode = PictureBoxSizeMode.AutoSiz
Dim Y As Image
Y = Image.FromFile("c:\yoursec
x.Image = Y
PictureBox1.Controls.Add(x
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
A picturebox simulates transparency by painting the "transparent" areas the color of the parent control. This is a problem when you want to overlap pictureboxes.
Another approach would be to get rid of the child pictureboxes completely and draw the images to your main picturebox directly.
'Load up an image from disk
Dim img As Image = Image.FromFile("c:\bw.gif" )
Dim bmp As New Bitmap(img)
img.Dispose()
'Create the graphics object to draw onto
Dim g As Graphics = PictureBox1.CreateGraphics
'Draw the images overlapping
g.DrawImage(bmp, 0, 0, bmp.Width, bmp.Height)
g.DrawImage(bmp, 20, 30, bmp.Width, bmp.Height)
Another approach would be to get rid of the child pictureboxes completely and draw the images to your main picturebox directly.
'Load up an image from disk
Dim img As Image = Image.FromFile("c:\bw.gif"
Dim bmp As New Bitmap(img)
img.Dispose()
'Create the graphics object to draw onto
Dim g As Graphics = PictureBox1.CreateGraphics
'Draw the images overlapping
g.DrawImage(bmp, 0, 0, bmp.Width, bmp.Height)
g.DrawImage(bmp, 20, 30, bmp.Width, bmp.Height)
ASKER
Ronald...Sorry but I think you missed the point, I need true transparency so if I drag a small picturebox over another the image below is visible. The Gifs in the small pictureboxes have transparent backgrounds, but this just picks up the parent picturebox's backcolor.
Erik ...I need these things to be moveable...not painted onto one big box.
As usually i'm off to try Idlemind's suggestion...hope its as excellent as always!
Erik ...I need these things to be moveable...not painted onto one big box.
As usually i'm off to try Idlemind's suggestion...hope its as excellent as always!
Use sprites:
Transparent GDI Sprite Library
http://www.vbaccelerator.com/home/VB/Code/vbMedia/Transparent_GDI_Sprite_Library/article.asp
Transparent GDI Sprite Library
http://www.vbaccelerator.com/home/VB/Code/vbMedia/Transparent_GDI_Sprite_Library/article.asp
I just pointed you to a VB6 sample.
The concept is the same for .NET.
Let's see if I can find a .NET sample...
The concept is the same for .NET.
Let's see if I can find a .NET sample...
ASKER
IdleMind comes with the goods again. Basically set the unwanted areas in my gifs to a color (bright pink) and then used his method to remove all areas of this color.
like
Private Sub PictureBox1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.Paint
Dim x As Image
x = Image.FromFile("c:\yoursec
e.Graphics.DrawImage(x, 1, 1)
End Sub
In this example I load the image in the paint event, this ofcourse isn't advisable, load it outside of the paint