Does anyone know how to make a frame transparent? I am just using the frame to separate groups of similar data on a form but I want it transparent so the form background can be seen.
Printable View
Does anyone know how to make a frame transparent? I am just using the frame to separate groups of similar data on a form but I want it transparent so the form background can be seen.
That's not as easy as it sounds, i'd try using the line control first.
You mean use a series of lines instead? OK, but how do I give the lines the etched effect?Quote:
i'd try using the line control first.
try getting sheridan controls.... u can make a it
by a property....
See this answer....you can do without the DLL if you use GetWindowLong and SetWindowLong API calls...
HTH,
Duncan
This only sets the backstyle of the contents of the frame i.e. the text boxs I have in the frame. I need to set the frame itself to transparent so only the border shows.
VB Code:
.SetWindowStyle WS_EX_TRANSPARENT, True
Makes the frame itself transparent...it may need to be redrawn though - try minimising and restoring the form and see if it goes transparent then...
VB 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 SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long Private Const WS_EX_TRANSPARENT = &H20& Private Const GWL_EXSTYLE = (-20) Private Const SWP_NOMOVE = &H2 Private Const SWP_NOSIZE = &H1 Private Const SWP_FRAMECHANGED = &H20 ' The frame changed: send WM_NCCALCSIZE Public Sub MakeFrameTransparent(ByVal fraThis As Frame) Dim lExStyle As Long lExStyle = GetWindowLong(fraThis.hwnd, GWL_EXSTYLE) lExStyle = lExStyle Or WS_EX_TRANSPARENT Call SetWindowLong(fraThis.hwnd, GWL_EXSTYLE, lExStyle) Call SetWindowPos(fraThis.hwnd, 0, 0, 0, 0, 0, SWP_NOMOVE + SWP_NOSIZE + SWP_FRAMECHANGED) End Sub
Note that you can make other windows transparent as well - the effect with a rich text box is particularily pleasing....
HTH,
Duncan
I can't get this to work. Is this the correct way to call it?
Private Sub Form_Load()
MakeFrameTransparent Frame1
End Sub
Me neither:(
That's correct..try putting apicture on your form so you can see that the frame is transparent...wiorks for me (VB5 on NT4)
I do have a picture covering the form and Frame1 in the middle. Using VB6 Enterprise, Win98SE
Am using VB6 and Win2000pro and just the textboxes are transparent in the frame. The labels - even when set to transparent, in the frame still aren't transparent.
Thanks anyway ;)
Try this?VB 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 SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long Private Const WS_EX_TRANSPARENT = &H20& Private Const GWL_EXSTYLE = (-20) Private Const SWP_NOMOVE = &H2 Private Const SWP_NOSIZE = &H1 Private Const SWP_FRAMECHANGED = &H20 Private Declare Function SetBkMode Lib "gdi32" Alias "SetBkMode" (ByVal hdc As Long, ByVal nBkMode As Long) As Long Private Declare Function GetDC Lib "user32" Alias "GetDC" (ByVal hwnd As Long) As Long Private Const TRANSPARENT = 1 Private Declare Function InvalidateRectLong Lib "user32" Alias "InvalidateRect" (ByVal hwnd As Long,ByVal lpRect As Long, ByVal bErase As Long) As Long Public Sub MakeFrameTransparent(ByVal fraThis As Frame) Dim lExStyle As Long lExStyle = GetWindowLong(fraThis.hwnd, GWL_EXSTYLE) lExStyle = lExStyle Or WS_EX_TRANSPARENT '\\ Set window style to be transparent Call SetWindowLong(fraThis.hwnd, GWL_EXSTYLE, lExStyle) '\\ make the fram backstyle transparent Call SetBKMode(GetDc(fraThis.hwnd),TRANSPARENT) '\\ Make frame window redraw itself Call SetWindowPos(fraThis.hwnd, 0, 0, 0, 0, 0, SWP_NOMOVE + SWP_NOSIZE + SWP_FRAMECHANGED) Call InvalidateRect(fraThis.hwnd, vbNull, True) fraThis.Refresh End Sub
Also - is your form's AutoRedraw set to false?
HTH,
Duncan
Yip the frame is transparent :D ..... including the border:mad: .
Do you know a way to leave the frame border visible?
Thanks a mill;)