My User Control does not produce transparent image.
The picture on the top is how it works now and the picture on the bottom is what I think it should have been.
Here is my UC code
Code:
Option Explicit
Private mPicture1 As StdPicture
Private mWidth As Integer
Private mHeight As Integer
Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
If Ambient.UserMode Then
BackStyle = 0 ' = Transparent
MaskColor = vbBlue
Set MaskPicture = Picture
End If
With PropBag
Set Picture1 = .ReadProperty("Picture1", Nothing)
End With
End Sub
Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
With PropBag
.WriteProperty "MaskColor", MaskColor, vbButtonFace
.WriteProperty "Picture1", Picture1, Nothing
End With
End Sub
Private Sub UserControl_Initialize()
UserControl.BackColor = vbWhite
UserControl.BackStyle = 0
MyPicture1.Move 0, 0, UserControl.ScaleWidth, UserControl.ScaleHeight
End Sub
Public Property Get MaskColor() As OLE_COLOR
MaskColor = UserControl.MaskColor
End Property
Public Property Let MaskColor(ByVal RHS As OLE_COLOR)
UserControl.MaskColor = RHS
PropertyChanged "MaskColor"
End Property
Public Property Get Picture1() As StdPicture
Set Picture1 = mPicture1
End Property
Public Property Set Picture1(ByVal RHS As StdPicture)
Set mPicture1 = RHS
Set MaskPicture = mPicture1
Set Picture = mPicture1
PropertyChanged "Picture1"
End Property
Public Property Get Width() As Integer
Width = UserControl.ScaleWidth
End Property
Public Property Let Width(ByVal newWidth As Integer)
UserControl.ScaleWidth = newWidth
End Property
Public Property Get Height() As Integer
Height = UserControl.ScaleHeight
End Property
Public Property Let Height(ByVal newHeight As Integer)
UserControl.ScaleHeight = newHeight
End Property
Private Sub UserControl_Paint()
Redraw
End Sub
Public Sub Redraw()
UserControl.MaskColor = UserControl.BackColor
Set UserControl.MaskPicture = UserControl.Image
UserControl.Refresh
End Sub
'==============================================
' Below from dilettante's code
'===============================================
Private Sub UserControl_InitProperties()
If Picture.Handle <> 0 Then
Size ScaleX(Picture.Width, vbHimetric, vbTwips), _
ScaleY(Picture.Height, vbHimetric, vbTwips)
End If
End Sub
Private Sub UserControl_Resize()
Size ScaleX(Picture.Width, vbHimetric, vbTwips), _
ScaleY(Picture.Height, vbHimetric, vbTwips)
End Sub
Public Sub LoadPicture(PIC As StdPicture)
Set Picture1 = PIC
End Sub
In Form_Load of the parent program I set the picture property of the control
Code:
Private Sub Form_Load()
ucTarget(0).LoadPicture Picture3.Picture
End Sub
Picture3 is a 9 x 9 image with red a horz line and a vert. line crossing in the center on a vbBlue surface. I use blue because that is the Mask color of the user control.
I didn't go back to try to find the original Project but I ripped, replaced, and re-ordered procedures to get working code again. Ended up with quite a bit less.
Not sure exactly what you were after here. This demo has a PictureBox used to source the first instance's Picture, the second instance I assigned a Picture to at design time.
Just for grins the UserControl has MousePointer = vbCrosshair but obviously you can change that.
You don't need any of this, just use an Image control with a transparent GIF.
Worry about function, form alone doesn't sell. If that were true we'd all be driving Kias and find ourselves with our thumbs out since they fall dead by the side of the road at the drop of a hat.
My User Control does not produce transparent image.
The picture on the top is how it works now and the picture on the bottom is what I think it should have been.
Here is my UC code
Code:
Option Explicit
Private mPicture1 As StdPicture
Private mWidth As Integer
Private mHeight As Integer
Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
If Ambient.UserMode Then
BackStyle = 0 ' = Transparent
MaskColor = vbBlue
Set MaskPicture = Picture
End If
With PropBag
Set Picture1 = .ReadProperty("Picture1", Nothing)
End With
End Sub
Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
With PropBag
.WriteProperty "MaskColor", MaskColor, vbButtonFace
.WriteProperty "Picture1", Picture1, Nothing
End With
End Sub
Private Sub UserControl_Initialize()
UserControl.BackColor = vbWhite
UserControl.BackStyle = 0
MyPicture1.Move 0, 0, UserControl.ScaleWidth, UserControl.ScaleHeight
End Sub
Public Property Get MaskColor() As OLE_COLOR
MaskColor = UserControl.MaskColor
End Property
Public Property Let MaskColor(ByVal RHS As OLE_COLOR)
UserControl.MaskColor = RHS
PropertyChanged "MaskColor"
End Property
Public Property Get Picture1() As StdPicture
Set Picture1 = mPicture1
End Property
Public Property Set Picture1(ByVal RHS As StdPicture)
Set mPicture1 = RHS
Set MaskPicture = mPicture1
Set Picture = mPicture1
PropertyChanged "Picture1"
End Property
Public Property Get Width() As Integer
Width = UserControl.ScaleWidth
End Property
Public Property Let Width(ByVal newWidth As Integer)
UserControl.ScaleWidth = newWidth
End Property
Public Property Get Height() As Integer
Height = UserControl.ScaleHeight
End Property
Public Property Let Height(ByVal newHeight As Integer)
UserControl.ScaleHeight = newHeight
End Property
Private Sub UserControl_Paint()
Redraw
End Sub
Public Sub Redraw()
UserControl.MaskColor = UserControl.BackColor
Set UserControl.MaskPicture = UserControl.Image
UserControl.Refresh
End Sub
'==============================================
' Below from dilettante's code
'===============================================
Private Sub UserControl_InitProperties()
If Picture.Handle <> 0 Then
Size ScaleX(Picture.Width, vbHimetric, vbTwips), _
ScaleY(Picture.Height, vbHimetric, vbTwips)
End If
End Sub
Private Sub UserControl_Resize()
Size ScaleX(Picture.Width, vbHimetric, vbTwips), _
ScaleY(Picture.Height, vbHimetric, vbTwips)
End Sub
Public Sub LoadPicture(PIC As StdPicture)
Set Picture1 = PIC
End Sub
In Form_Load of the parent program I set the picture property of the control
Code:
Private Sub Form_Load()
ucTarget(0).LoadPicture Picture3.Picture
End Sub
Picture3 is a 9 x 9 image with red a horz line and a vert. line crossing in the center on a vbBlue surface. I use blue because that is the Mask color of the user control.