This effect is like if you have VISTA and you are required to confirm your choice...... UAC stuff. The whole sceen dims a little and in the middle of the screen you have one bright window.
Back to Access - the command to do this (which changes the opacity of the form) is (other than the module stuff.....0 would be transperant.
SetFormOpacity Me, 0.7
I am wondering if we can use this to change the opacity of Me.Detail.BackColor?
Your hypothesis sounds interesting and a bit fun...but I have no clue how to pull it off and don't have time to research it. Let us know what you come up with.
It seems that VB can do this easily with for example the TransparencyKey. Where you can allocate a color to be transparent. You can even click through the transperant section to something below it.
But this is all not in VBA.
I think, I guess, to change a form is VBA I am going to have to pull out some API stuff. For me that is going to be a miracle, but I will have a poke around.
For a beginner Google, and try, test and try and test again are my methods.
and seen from the example above the "SetLayeredWindowAttributes Function" is the key.
So I created a simple example as follows
this went into a module
Code:
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 crKey As Long, _
ByVal bAlpha As Byte, _
ByVal dwFlags As Long) As Long
Private Const LWA_COLORKEY As Long = &H1
Private Const LWA_ALPHA As Long = &H2
Private Const GWL_EXSTYLE As Long = -20
Private Const WS_EX_LAYERED As Long = &H80000
Public Sub SetFormOpacity(frm As Form, trns As Long, sngOpacity As Single)
Dim lngStyle As Long
' get the current window style, then set transparency
lngStyle = GetWindowLong(frm.hwnd, GWL_EXSTYLE)
'SetWindowLong frm.hwnd, GWL_EXSTYLE, lngStyle Or WS_EX_LAYERED
SetLayeredWindowAttributes frm.hwnd, trns, (sngOpacity * 255), LWA_ALPHA Or LWA_COLORKEY
End Sub
the make a a form and this this in the on load
Code:
Dim transcolor As Long
transcolor = RGB(100, 200, 100)
Me.Detail.BackColor = transcolor
Me.Painting = False
SetFormOpacity Me, transcolor, 1
Me.Painting = True
the form also should be
pop-up - yes
record selector - no
borders - none
Detail.BackColor = 6604900 (which should be RGB(100,200,100)
I added a simple close button.
Then open your form. You will get a transparent form except for your button.
Now if I add a nice picture to this with a shadow and transperant otherwise it should appear to be "the form", put controls on it and I have my "skin" eyecandy
and seen from the example above the "SetLayeredWindowAttributes Function" is the key.
So I created a simple example as follows
this went into a module
Code:
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 crKey As Long, _
ByVal bAlpha As Byte, _
ByVal dwFlags As Long) As Long
Private Const LWA_COLORKEY As Long = &H1
Private Const LWA_ALPHA As Long = &H2
Private Const GWL_EXSTYLE As Long = -20
Private Const WS_EX_LAYERED As Long = &H80000
Public Sub SetFormOpacity(frm As Form, trns As Long, sngOpacity As Single)
Dim lngStyle As Long
' get the current window style, then set transparency
lngStyle = GetWindowLong(frm.hwnd, GWL_EXSTYLE)
'SetWindowLong frm.hwnd, GWL_EXSTYLE, lngStyle Or WS_EX_LAYERED
SetLayeredWindowAttributes frm.hwnd, trns, (sngOpacity * 255), LWA_ALPHA Or LWA_COLORKEY
End Sub
the make a a form and this this in the on load
Code:
Dim transcolor As Long
transcolor = RGB(100, 200, 100)
Me.Detail.BackColor = transcolor
Me.Painting = False
SetFormOpacity Me, transcolor, 1
Me.Painting = True
the form also should be
pop-up - yes
record selector - no
borders - none
Detail.BackColor = 6604900 (which should be RGB(100,200,100)
I added a simple close button.
Then open your form. You will get a transparent form except for your button.
Now if I add a nice picture to this with a shadow and transperant otherwise it should appear to be "the form", put controls on it and I have my "skin" eyecandy
There is one thing though. I do not suppose anyone can get VBA and GDI+ to "draw" a png image with ARGB colors (alpha channels) That would really make these transparent forms come alive with eyecandy.
Shadow, thanks for the response. I tried using the code from the form that has the transparent holes, I imported all the modules and the form itself when I open the imported from if works fine, I have pasted into my form all the code from the imported form, I keep geting
apiRGB RGBx3(0), lngColor, 4
apiRGB sub or function not defined, can not figure out why as again the imported form works fine, any insight into why?
The code is not mine and I've never used it. However, just browsing through the project, I see that there's a form called frmCombineRgn which has a function declaration for apiRGB. Do you have this in your project?
Sorry to dig up an old thread, but I had something to add, georgedwilkinson code wasn't working for me, here is a code that is almost the same, but works.
For the Module:
Code:
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 crKey As Long, _
ByVal bAlpha As Byte, _
ByVal dwFlags As Long) As Long
Private Const LWA_ALPHA As Long = &H2
Private Const GWL_EXSTYLE As Long = -20
Private Const WS_EX_LAYERED As Long = &H80000
Public Sub SetFormOpacity(frm As Form, sngOpacity As Single, TColor As Long)
Dim lngStyle As Long
' get the current window style, then set transparency
lngStyle = GetWindowLong(frm.hwnd, GWL_EXSTYLE)
SetWindowLong frm.hwnd, GWL_EXSTYLE, lngStyle Or WS_EX_LAYERED
SetLayeredWindowAttributes frm.hwnd, TColor, (sngOpacity * 255), LWA_ALPHA
End Sub
And in the From on the Form_Load()
Code:
Private Sub Form_load()
Dim Transp As Long
Transp = RGB(0, 0, 0) 'This is the color you want your background to be
Me.Detail.BackColor = Transp
Me.Painting = False
SetFormOpacity Me, 0.5, Transp
Me.Painting = True
End Sub
and in the SetFormOpacy sub:
SetLayeredWindowAttributes frm.hwnd, TColor, (sngOpacity * 255), LWA_ALPHA or LWA_COLORKEY
When I added the two of these to my code, the form was no longer visible, and the TColor adjusted the transparency of the controls on the form, not the form itself.
Sorry to dig up an old thread, but I had something to add, georgedwilkinson code wasn't working for me, here is a code that is almost the same, but works.
For the Module:
Code:
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 crKey As Long, _
ByVal bAlpha As Byte, _
ByVal dwFlags As Long) As Long
Private Const LWA_ALPHA As Long = &H2
Private Const GWL_EXSTYLE As Long = -20
Private Const WS_EX_LAYERED As Long = &H80000
Public Sub SetFormOpacity(frm As Form, sngOpacity As Single, TColor As Long)
Dim lngStyle As Long
' get the current window style, then set transparency
lngStyle = GetWindowLong(frm.hwnd, GWL_EXSTYLE)
SetWindowLong frm.hwnd, GWL_EXSTYLE, lngStyle Or WS_EX_LAYERED
SetLayeredWindowAttributes frm.hwnd, TColor, (sngOpacity * 255), LWA_ALPHA
End Sub
And in the From on the Form_Load()
Code:
Private Sub Form_load()
Dim Transp As Long
Transp = RGB(0, 0, 0) 'This is the color you want your background to be
Me.Detail.BackColor = Transp
Me.Painting = False
SetFormOpacity Me, 0.5, Transp
Me.Painting = True
End Sub