Dears,
How can i make a Picturebox Transparent. Please suggest the way
Printable View
Dears,
How can i make a Picturebox Transparent. Please suggest the way
This question was asked for several times.... Do a search on the forum....
Click here to search :wave:
IMO, the easiest way to achieve transparency is to use a UserControl, which
has the MaskPicture and MaskColor properties. The code below only exposes
two properties, Picture and MaskColor. Add a new UserControl to your project and
insert the code below. Once you have sited it on a form, assign a picture. Then
assign a MaskColor and that will be the transparent color.
As written, this does nothing more than display the picture. You will likely want to
assign some PictureBox events, such as MouseDown, etc.
Code:Option Explicit
Private Sub UserControl_InitProperties()
BackStyle = 0 'transparent
MaskColor = vbMagenta
End Sub
Public Property Get MaskColor() As OLE_COLOR
MaskColor = UserControl.MaskColor
End Property
Public Property Let MaskColor(ByVal New_MaskColor As OLE_COLOR)
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
'remove if you don't want autosize
Width = ScaleX(Picture.Width, vbHimetric, vbPixels) * Screen.TwipsPerPixelX
Height = ScaleY(Picture.Height, vbHimetric, vbPixels) * Screen.TwipsPerPixelY
PropertyChanged "Picture"
End Property
Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
UserControl.MaskColor = PropBag.ReadProperty("MaskColor", vbMagenta)
Set Picture = PropBag.ReadProperty("Picture", Nothing)
Set UserControl.MaskPicture = UserControl.Picture
End Sub
Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
Call PropBag.WriteProperty("MaskColor", UserControl.MaskColor, vbMagenta)
Call PropBag.WriteProperty("Picture", Picture, Nothing)
End Sub