Results 1 to 14 of 14

Thread: How to make a picturebox transparent

  1. #1

    Thread Starter
    Fanatic Member technorobbo's Avatar
    Join Date
    Dec 2008
    Location
    Chicago
    Posts
    864

    How to make a picturebox transparent

    Here's a technique that I worked out to make a picturebox see thru.

    Layered windows are considered the top most window with no parent - but if you take a picturebox set it's parent to zero you can make it transparent then set the form as it's parent again. you must refresh immediately to lock the graphics. the drawback is that the coordinates are now screen coordinates but I use ClientToScreen and a timer to keep it aligned.
    Attached Files Attached Files
    Last edited by technorobbo; May 5th, 2009 at 07:01 PM.
    Have Fun,

    TR
    _____________________________
    Check out my Alpha DogFighter2D Game Demo and Source code. Direct Download:http://home.comcast.net/~technorobbo/Alpha.zip or Read about it in the forum:http://www.vbforums.com/showthread.php?t=551700. Now in 3D!!! http://home.comcast.net/~technorobbo/AlPha3D.zip or read about it in the forum: http://www.vbforums.com/showthread.php?goto=newpost&t=552560 and IChessChat3D internet chess game

  2. #2

    Thread Starter
    Fanatic Member technorobbo's Avatar
    Join Date
    Dec 2008
    Location
    Chicago
    Posts
    864

    Re: How to make a picturebox transparent

    And here's a usercontrol example:
    Attached Files Attached Files
    • File Type: zip UC.zip (52.0 KB, 1919 views)
    Last edited by technorobbo; May 5th, 2009 at 07:02 PM.
    Have Fun,

    TR
    _____________________________
    Check out my Alpha DogFighter2D Game Demo and Source code. Direct Download:http://home.comcast.net/~technorobbo/Alpha.zip or Read about it in the forum:http://www.vbforums.com/showthread.php?t=551700. Now in 3D!!! http://home.comcast.net/~technorobbo/AlPha3D.zip or read about it in the forum: http://www.vbforums.com/showthread.php?goto=newpost&t=552560 and IChessChat3D internet chess game

  3. #3
    Fanatic Member coolcurrent4u's Avatar
    Join Date
    Apr 2008
    Location
    *****
    Posts
    993

    Re: How to make a picturebox transparent

    Your links are dead. Can you pls correct them?

  4. #4

    Thread Starter
    Fanatic Member technorobbo's Avatar
    Join Date
    Dec 2008
    Location
    Chicago
    Posts
    864

    Re: How to make a picturebox transparent

    Here, I uploaded them to the post, wonder what happened to that thread?
    Have Fun,

    TR
    _____________________________
    Check out my Alpha DogFighter2D Game Demo and Source code. Direct Download:http://home.comcast.net/~technorobbo/Alpha.zip or Read about it in the forum:http://www.vbforums.com/showthread.php?t=551700. Now in 3D!!! http://home.comcast.net/~technorobbo/AlPha3D.zip or read about it in the forum: http://www.vbforums.com/showthread.php?goto=newpost&t=552560 and IChessChat3D internet chess game

  5. #5
    Junior Member
    Join Date
    Feb 2009
    Posts
    28

    Re: How to make a picturebox transparent

    thanks

  6. #6
    Fanatic Member coolcurrent4u's Avatar
    Join Date
    Apr 2008
    Location
    *****
    Posts
    993

    Re: How to make a picturebox transparent

    Quote Originally Posted by technorobbo View Post
    Here, I uploaded them to the post, wonder what happened to that thread?
    Hello Thanks for the quick respons!

    But i wanted a transparent picturebox to solve the problem i was having.

    I had a tabstrip control in xp style but the frame control is not transparent.

    So i thot if i could make either the frame or picture box transparent , it will do just fine.

    i have search for transparent picture and frame, but its either to complex (as use of like three four modules ) or it has a bug

    when i use ur solution, it does not get transparent when i put controls on the picture box

    i have attached the effect am trying to emulate. the winxp system diloge box
    any ideas

    thanks once again
    Attached Images Attached Images  

  7. #7

    Thread Starter
    Fanatic Member technorobbo's Avatar
    Join Date
    Dec 2008
    Location
    Chicago
    Posts
    864

    Re: How to make a picturebox transparent

    I'm not clear from the image what is transparent, are you trying to grey out a button?
    Have Fun,

    TR
    _____________________________
    Check out my Alpha DogFighter2D Game Demo and Source code. Direct Download:http://home.comcast.net/~technorobbo/Alpha.zip or Read about it in the forum:http://www.vbforums.com/showthread.php?t=551700. Now in 3D!!! http://home.comcast.net/~technorobbo/AlPha3D.zip or read about it in the forum: http://www.vbforums.com/showthread.php?goto=newpost&t=552560 and IChessChat3D internet chess game

  8. #8
    Fanatic Member coolcurrent4u's Avatar
    Join Date
    Apr 2008
    Location
    *****
    Posts
    993

    Question Re: How to make a picturebox transparent

    Quote Originally Posted by technorobbo View Post
    I'm not clear from the image what is transparent, are you trying to grey out a button?
    From the image you'll see that the frame control with blue text is transparent (ie the gradient of the tabstrip show through, just like a transparent label control)

  9. #9

    Thread Starter
    Fanatic Member technorobbo's Avatar
    Join Date
    Dec 2008
    Location
    Chicago
    Posts
    864

    Re: How to make a picturebox transparent

    Hey your right, I never noticed that before - but that dialog is a layered top level window, not a control and making those semi-transparent is easy. It's the windows control like a picturebox that takes some effort.

    Here - Make form, put a bunch of controls in it and put this code in it.
    Code:
    Option Explicit
    Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
    Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
    Private Declare Function SetLayeredWindowAttributes Lib "user32" (ByVal hwnd As Long, ByVal CRef As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long
    Private Const GWL_EXSTYLE = (-20)
    Private Const WS_EX_LAYERED = &H80000
    Private Const LWA_ALPHA = &H2&
    
    Dim OldStyle As Long
    
    Private Sub Form_Load()
    OldStyle = GetWindowLong(Me.hwnd, GWL_EXSTYLE)
    Me.Show
    
    Call SetWindowLong(Me.hwnd, GWL_EXSTYLE, GetWindowLong(Me.hwnd, GWL_EXSTYLE) Or WS_EX_LAYERED)
    Call SetLayeredWindowAttributes(Me.hwnd, 0, 128, LWA_ALPHA)
    
    End Sub
    It and all it's controls will be see thru.

    Change the 128 to 240 and it will be slightly transparent.
    Have Fun,

    TR
    _____________________________
    Check out my Alpha DogFighter2D Game Demo and Source code. Direct Download:http://home.comcast.net/~technorobbo/Alpha.zip or Read about it in the forum:http://www.vbforums.com/showthread.php?t=551700. Now in 3D!!! http://home.comcast.net/~technorobbo/AlPha3D.zip or read about it in the forum: http://www.vbforums.com/showthread.php?goto=newpost&t=552560 and IChessChat3D internet chess game

  10. #10
    Fanatic Member coolcurrent4u's Avatar
    Join Date
    Apr 2008
    Location
    *****
    Posts
    993

    Re: How to make a picturebox transparent

    This is making the whole form transparent

    I just want the picture box made transparent or translucent. this means it still acts as a container, but will host controls because am using it with a tabstrip see the attached picture.

    or if you can make the frame control transparent better

  11. #11

    Thread Starter
    Fanatic Member technorobbo's Avatar
    Join Date
    Dec 2008
    Location
    Chicago
    Posts
    864

    Re: How to make a picturebox transparent

    A User Control Can be used as a container and has a tranpsparent background. Have you tried using that? If you only want to use it as a container it may be perfect for your needs.
    Have Fun,

    TR
    _____________________________
    Check out my Alpha DogFighter2D Game Demo and Source code. Direct Download:http://home.comcast.net/~technorobbo/Alpha.zip or Read about it in the forum:http://www.vbforums.com/showthread.php?t=551700. Now in 3D!!! http://home.comcast.net/~technorobbo/AlPha3D.zip or read about it in the forum: http://www.vbforums.com/showthread.php?goto=newpost&t=552560 and IChessChat3D internet chess game

  12. #12
    Fanatic Member coolcurrent4u's Avatar
    Join Date
    Apr 2008
    Location
    *****
    Posts
    993

    Re: How to make a picturebox transparent

    ok help me with some code

  13. #13

    Thread Starter
    Fanatic Member technorobbo's Avatar
    Join Date
    Dec 2008
    Location
    Chicago
    Posts
    864

    Re: How to make a picturebox transparent

    Sure - what's going in the container?

    Here's a quick example - the only issue with usercontrols is that transparent labels disappear but here's an easy work around:

    http://home.comcast.net/~technorobbo/FrameTrans.zip
    Stay away from Arial because TrueType Fonts look a little sloppy. Stick with Bitmap Fonts Like MS Sans Serif.
    Last edited by technorobbo; May 16th, 2009 at 12:06 PM.
    Have Fun,

    TR
    _____________________________
    Check out my Alpha DogFighter2D Game Demo and Source code. Direct Download:http://home.comcast.net/~technorobbo/Alpha.zip or Read about it in the forum:http://www.vbforums.com/showthread.php?t=551700. Now in 3D!!! http://home.comcast.net/~technorobbo/AlPha3D.zip or read about it in the forum: http://www.vbforums.com/showthread.php?goto=newpost&t=552560 and IChessChat3D internet chess game

  14. #14
    Fanatic Member coolcurrent4u's Avatar
    Join Date
    Apr 2008
    Location
    *****
    Posts
    993

    Re: How to make a picturebox transparent

    i'ltry this one out.thanks

Posting Permissions

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



Click Here to Expand Forum to Full Width