Results 1 to 2 of 2

Thread: Transparent Picturebox Question

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Oct 2000
    Posts
    1,463

    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!
    Last edited by WarrenW; Dec 11th, 2005 at 01:54 PM.

  2. #2
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    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:
    1. Option Explicit
    2.  
    3. Private Sub UserControl_Initialize()
    4.     UserControl.BackStyle = 0
    5. End Sub
    6.  
    7. Public Property Get MaskColor() As Long
    8.     MaskColor = UserControl.MaskColor
    9. End Property
    10.  
    11. Public Property Let MaskColor(ByVal New_MaskColor As Long)
    12.     UserControl.MaskColor() = New_MaskColor
    13.     PropertyChanged "MaskColor"
    14. End Property
    15.  
    16. Public Property Get Picture() As Picture
    17.     Set Picture = UserControl.Picture
    18. End Property
    19.  
    20. Public Property Set Picture(ByVal New_Picture As Picture)
    21.     Set UserControl.Picture = New_Picture
    22.     Set UserControl.MaskPicture = New_Picture
    23.     PropertyChanged "Picture"
    24. End Property
    25.  
    26. Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
    27.     UserControl.MaskColor = PropBag.ReadProperty("MaskColor", vbWhite)
    28.     Set Picture = PropBag.ReadProperty("Picture", Nothing)
    29. End Sub
    30.  
    31. Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
    32.     Call PropBag.WriteProperty("MaskColor", UserControl.MaskColor, vbWhite)
    33.     Call PropBag.WriteProperty("Picture", Picture, Nothing)
    34. End Sub
    Now to use it, draw it onto your form, let's call it MyControl
    VB Code:
    1. MyControl.MaskColor = vbWhite
    2.     Set MyControl.Picture = LoadPicture("whatever.gif")
    If move over your existing controls you will see it has a transparent background

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width