Post Reply 
PictureBox Background
Author Message
Ac_K
I See K

Posts: 141.5490
Threads: 5
Joined: 9th Jun 2007
Reputation: -3.19624
E-Pigs: 12.2039
Offline
Post: #1
PictureBox Background
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:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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)

(This post was last modified: 20/11/2007 12:57 PM by Ac_K.)
20/11/2007 12:57 PM
Find all posts by this user Quote this message in a reply
Ac_K
I See K

Posts: 141.5490
Threads: 5
Joined: 9th Jun 2007
Reputation: -3.19624
E-Pigs: 12.2039
Offline
Post: #2
RE: PictureBox Background
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
20/11/2007 04:09 PM
Find all posts by this user Quote this message in a reply
ZiNgA BuRgA
Smart Alternative

Posts: 17,023.4213
Threads: 1,174
Joined: 19th Jan 2007
Reputation: -1.71391
E-Pigs: 446.0333
Offline
Post: #3
RE: PictureBox Background
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...
20/11/2007 08:54 PM
Visit this user's website Find all posts by this user Quote this message in a reply
Post Reply 


Forum Jump:


User(s) browsing this thread: 1 Guest(s)

 Quick Theme: