Endless Paradigm

Full Version: PictureBox Background
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi all !

I would put a Picturebox on another Picturebox... The first it's a background... The second it's an icon...
But for the second PictureBox I would have a transparent background.
And I would modify the transparency of the content of PictureBox.

The problem it's I don't find how put a transparency background on a Picturebox, So I try to use PNG with GDI, but the background it's already colored...

I find a function :

Code:
Private Declare Function GetWindowDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
Private Declare Function CreateRectRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Private Declare Function CombineRgn Lib "gdi32" (ByVal hDestRgn As Long, ByVal hSrcRgn1 As Long, ByVal hSrcRgn2 As Long, ByVal nCombineMode As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Private Declare Function SetWindowRgn Lib "user32" (ByVal hwnd As Long, ByVal hRgn As Long, ByVal bRedraw As Boolean) As Long

Public Sub BackgroundTransparent(Objet As Object)
    Dim CouleurBackground As Long
    Dim hdcObjet As Long, RectFinal As Long, NewRect As Long
    Dim x As Integer, y As Integer
    
    On Error Resume Next
        hdcObjet = GetWindowDC(Objet.hwnd)
        CouleurBackground = GetPixel(hdcObjet, 0, 0)
    
        If CouleurBackground = -1 Then Exit Sub
        Objet.BackColor = CouleurBackground
        RectFinal = CreateRectRgn(0, 0, Objet.width, Objet.height)
    
        For y = 0 To Objet.height
            For x = 0 To Objet.width
                If GetPixel(hdcObjet, x, y) = CouleurBackground Then
                    NewRect = CreateRectRgn(x, y, x + 1, y + 1)
                    CombineRgn RectFinal, RectFinal, NewRect, 4
                    DeleteObject (NewRect)
                End If
            Next x
            x = 0
        Next y
    
        SetWindowRgn Objet.hwnd, RectFinal, True
        DeleteObject (RectFinal)
End Sub


But I can't modify the picturebox after...
Help me please (ZiNgA BuRgA ??? ;P)

http://www.vbforums.com/showthread.php?t=492028

I made what I would... I use this OCX... I try to add the usercontrol in my project...
Now I could work on my viewer for my editor ;P
You can just use an image control rather than a picture control for the icon, or just draw the image icon onto the picture box...
Reference URL's