dcsimg
Results 1 to 9 of 9

Thread: [RESOLVED] User Control Transparency Issue

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2017
    Posts
    207

    Resolved [RESOLVED] User Control Transparency Issue

    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.
    Attached Images Attached Images   

  2. #2
    Frenzied Member some1uk03's Avatar
    Join Date
    Jun 2006
    Location
    London, UK
    Posts
    1,504

    Re: User Control Transparency Issue

    Question: Is it really necessary to be using a Picture?
    I'm sure it would be faster to simply draw the Lines via API's or the + symbol?
    _____________________________________________________________________

    ----If this post has helped you. Please take time to Rate it.
    ----If you've solved your problem, then please mark it as RESOLVED from Thread Tools.



  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Mar 2017
    Posts
    207

    Re: User Control Transparency Issue

    Yes, I need the UC

  4. #4
    PowerPoster
    Join Date
    Feb 2006
    Posts
    20,800

    Re: User Control Transparency Issue

    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.

    Name:  sshot.png
Views: 80
Size:  1.4 KB

    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.
    Attached Files Attached Files

  5. #5

  6. #6
    PowerPoster
    Join Date
    Feb 2006
    Posts
    20,800

    Re: User Control Transparency Issue

    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.

  7. #7
    Hyperactive Member
    Join Date
    Feb 2014
    Location
    Norfolk UK (inbred)
    Posts
    442

    Re: User Control Transparency Issue

    Quote Originally Posted by dilettante View Post
    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 wife has a Kia, 27,000 miles and all of it utterly reliable. Not once near a garage except for petrol. Cost 500.

    Transparent GIF does sound like the easiest option.

  8. #8
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    18,572

    Re: User Control Transparency Issue

    What happens if you change the UC backcolor to the MaskColor? On Initialize, it is White and unless MaskColor public property set, it remains white.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  9. #9
    Hyperactive Member
    Join Date
    Aug 2016
    Posts
    377

    Re: User Control Transparency Issue

    Quote Originally Posted by Ordinary Guy View Post
    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.
    Code:
             AutoRedraw = True
             Cls
             BackColor = MaskColor
             BackStyle = 0
             UserControl.PaintPicture Picture1.Picture, 0, 0
                
             AutoRedraw = False
    
             Set MaskPicture = Image 'Render with mask transparency.
    Last edited by xxdoc123; Sep 30th, 2019 at 12:13 AM.

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width