Transparent Picturebox Question
Hello,
I know that many people have asked how to make a transparent image on here. Most of the examples I have used have not worked for my need. What I want to do is make an image transparent by color selection (white mainly) and then with my own routines move the image around on the form. I don't want the form just to be the background of the image. I want to move the image over other controls and see them properly in the transparent area.
Does anyone have an example for this?
ALSO, there will be a different image used everytime so it must work for any image with a white background.
Thanks!
Re: Transparent Picturebox Question
What I like to do is use a UserControl rather than a picturebox.
Create a usercontrol and add the following properties
VB Code:
Option Explicit
Private Sub UserControl_Initialize()
UserControl.BackStyle = 0
End Sub
Public Property Get MaskColor() As Long
MaskColor = UserControl.MaskColor
End Property
Public Property Let MaskColor(ByVal New_MaskColor As Long)
UserControl.MaskColor() = New_MaskColor
PropertyChanged "MaskColor"
End Property
Public Property Get Picture() As Picture
Set Picture = UserControl.Picture
End Property
Public Property Set Picture(ByVal New_Picture As Picture)
Set UserControl.Picture = New_Picture
Set UserControl.MaskPicture = New_Picture
PropertyChanged "Picture"
End Property
Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
UserControl.MaskColor = PropBag.ReadProperty("MaskColor", vbWhite)
Set Picture = PropBag.ReadProperty("Picture", Nothing)
End Sub
Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
Call PropBag.WriteProperty("MaskColor", UserControl.MaskColor, vbWhite)
Call PropBag.WriteProperty("Picture", Picture, Nothing)
End Sub
Now to use it, draw it onto your form, let's call it MyControl
VB Code:
MyControl.MaskColor = vbWhite
Set MyControl.Picture = LoadPicture("whatever.gif")
If move over your existing controls you will see it has a transparent background