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.
Last edited by technorobbo; May 5th, 2009 at 07:01 PM.
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)
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.
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
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.