
transparent OCX with transparent label
Instead of using a Label control, just print the caption on the UserControl
and transfer it to the MaskPicture.
Here is an example of a simple UserControl with a Caption property only:
Option Explicit
'Property Variables:
Dim msCaption As String
Public Property Get Caption() As String
Caption = msCaption
End Property
Public Property Let Caption(ByVal New_Caption As String)
msCaption = New_Caption
PropertyChanged "Caption"
Call DrawCaption
End Property
'Initialize Properties for User Control
Private Sub UserControl_InitProperties()
msCaption = UserControl.Ambient.DisplayName
End Sub
'Load property values from storage
Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
msCaption = PropBag.ReadProperty("Caption", "")
Call DrawCaption
End Sub
Private Sub UserControl_Resize()
Call DrawCaption
End Sub
'Write property values to storage
Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
Call PropBag.WriteProperty("Caption", msCaption, "")
End Sub
Private Sub DrawCaption()
With UserControl
'Turn on AutoRedraw, so we can draw to the Image
.AutoRedraw = True
'Clear previous Caption
Set .Picture = LoadPicture()
.Cls
'Center the Caption
.CurrentX = (.ScaleWidth - .TextWidth(msCaption)) / 2
.CurrentY = (.ScaleHeight - .TextHeight(msCaption)) / 2
'Print the Caption
UserControl.Print msCaption
'Match the MaskColor to the BackColor for transparency
.MaskColor = .BackColor
'Persist the Image to the Picture
Set .Picture = .Image
'Pass the same Image to the MaskPicture
Set .MaskPicture = .Image
'No need for AutoRedraw anymore
.AutoRedraw = False
'Make it transparent
.BackStyle = 0
End With
End Sub
Quote:
> Someone have an example about how create an transparent custom control
with
> a Transparent Label
> Eugenio