Results 1 to 15 of 15

Thread: Make frame transparent?

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2001
    Posts
    1,384

    Make frame transparent?

    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.
    Mel

  2. #2
    Not NoteMe SLH's Avatar
    Join Date
    Mar 2002
    Location
    192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
    Posts
    3,051
    That's not as easy as it sounds, i'd try using the line control first.
    Quotes:
    "I am getting better then you guys.." NoteMe, on his leet english skills.
    "And I am going to meat her again later on tonight." NoteMe
    "I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
    "my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
    Have I helped you? Please Rate my posts.


  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2001
    Posts
    1,384
    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?
    Mel

  4. #4
    khalik
    Guest
    try getting sheridan controls.... u can make a it
    by a property....

  5. #5
    Frenzied Member MerrionComputin's Avatar
    Join Date
    Apr 2001
    Location
    Dublin, Ireland
    Posts
    1,616
    See this answer....you can do without the DLL if you use GetWindowLong and SetWindowLong API calls...


    HTH,
    Duncan
    ----8<---------------------------------------
    NEW - The .NET printer queue monitor component
    ----8<---------------------------------------
    Now with Examples of use

  6. #6

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2001
    Posts
    1,384

    MerrionComputin

    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.
    Mel

  7. #7
    Frenzied Member MerrionComputin's Avatar
    Join Date
    Apr 2001
    Location
    Dublin, Ireland
    Posts
    1,616
    VB Code:
    1. .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...
    ----8<---------------------------------------
    NEW - The .NET printer queue monitor component
    ----8<---------------------------------------
    Now with Examples of use

  8. #8
    Frenzied Member MerrionComputin's Avatar
    Join Date
    Apr 2001
    Location
    Dublin, Ireland
    Posts
    1,616

    Code (without need for EventVB.dll)

    VB Code:
    1. Option Explicit
    2.  
    3. Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
    4. Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
    5. 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
    6. Private Const WS_EX_TRANSPARENT = &H20&
    7. Private Const GWL_EXSTYLE = (-20)
    8. Private Const SWP_NOMOVE = &H2
    9. Private Const SWP_NOSIZE = &H1
    10. Private Const SWP_FRAMECHANGED = &H20        '  The frame changed: send WM_NCCALCSIZE
    11.  
    12. Public Sub MakeFrameTransparent(ByVal fraThis As Frame)
    13.  
    14. Dim lExStyle As Long
    15.  
    16. lExStyle = GetWindowLong(fraThis.hwnd, GWL_EXSTYLE)
    17. lExStyle = lExStyle Or WS_EX_TRANSPARENT
    18.  
    19. Call SetWindowLong(fraThis.hwnd, GWL_EXSTYLE, lExStyle)
    20. Call SetWindowPos(fraThis.hwnd, 0, 0, 0, 0, 0, SWP_NOMOVE + SWP_NOSIZE + SWP_FRAMECHANGED)
    21.  
    22. End Sub

    Note that you can make other windows transparent as well - the effect with a rich text box is particularily pleasing....

    HTH,
    Duncan
    ----8<---------------------------------------
    NEW - The .NET printer queue monitor component
    ----8<---------------------------------------
    Now with Examples of use

  9. #9
    Hyperactive Member
    Join Date
    May 2001
    Posts
    414

    Re: Code (without need for EventVB.dll)

    I can't get this to work. Is this the correct way to call it?

    Private Sub Form_Load()
    MakeFrameTransparent Frame1
    End Sub

  10. #10

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2001
    Posts
    1,384
    Me neither
    Mel

  11. #11
    Frenzied Member MerrionComputin's Avatar
    Join Date
    Apr 2001
    Location
    Dublin, Ireland
    Posts
    1,616
    That's correct..try putting apicture on your form so you can see that the frame is transparent...wiorks for me (VB5 on NT4)
    ----8<---------------------------------------
    NEW - The .NET printer queue monitor component
    ----8<---------------------------------------
    Now with Examples of use

  12. #12
    Hyperactive Member
    Join Date
    May 2001
    Posts
    414
    I do have a picture covering the form and Frame1 in the middle. Using VB6 Enterprise, Win98SE

  13. #13

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2001
    Posts
    1,384
    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
    Mel

  14. #14
    Frenzied Member MerrionComputin's Avatar
    Join Date
    Apr 2001
    Location
    Dublin, Ireland
    Posts
    1,616
    VB Code:
    1. Option Explicit
    2.  
    3. Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
    4. Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
    5. 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
    6. Private Const WS_EX_TRANSPARENT = &H20&
    7. Private Const GWL_EXSTYLE = (-20)
    8. Private Const SWP_NOMOVE = &H2
    9. Private Const SWP_NOSIZE = &H1
    10. Private Const SWP_FRAMECHANGED = &H20    
    11. Private Declare Function SetBkMode Lib "gdi32" Alias "SetBkMode" (ByVal hdc As Long, ByVal nBkMode As Long) As Long
    12. Private Declare Function GetDC Lib "user32" Alias "GetDC" (ByVal hwnd As Long) As Long
    13. Private Const TRANSPARENT = 1
    14. Private Declare Function InvalidateRectLong Lib "user32" Alias "InvalidateRect" (ByVal hwnd As Long,ByVal lpRect As Long, ByVal bErase As Long) As Long
    15.  
    16.  
    17. Public Sub MakeFrameTransparent(ByVal fraThis As Frame)
    18.  
    19. Dim lExStyle As Long
    20.  
    21. lExStyle = GetWindowLong(fraThis.hwnd, GWL_EXSTYLE)
    22. lExStyle = lExStyle Or WS_EX_TRANSPARENT
    23.  
    24. '\\ Set window style to be transparent
    25. Call SetWindowLong(fraThis.hwnd, GWL_EXSTYLE, lExStyle)
    26. '\\ make the fram backstyle transparent
    27. Call SetBKMode(GetDc(fraThis.hwnd),TRANSPARENT)
    28. '\\ Make frame window redraw itself
    29. Call SetWindowPos(fraThis.hwnd, 0, 0, 0, 0, 0, SWP_NOMOVE + SWP_NOSIZE + SWP_FRAMECHANGED)
    30. Call InvalidateRect(fraThis.hwnd, vbNull, True)
    31. fraThis.Refresh
    32.  
    33. End Sub
    Try this?
    Also - is your form's AutoRedraw set to false?

    HTH,
    Duncan
    ----8<---------------------------------------
    NEW - The .NET printer queue monitor component
    ----8<---------------------------------------
    Now with Examples of use

  15. #15

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2001
    Posts
    1,384
    Yip the frame is transparent ..... including the border .
    Do you know a way to leave the frame border visible?

    Thanks a mill
    Mel

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