Results 1 to 6 of 6

Thread: Is there a way to make a form transparent?

  1. #1

    Thread Starter
    Lively Member rotcrules's Avatar
    Join Date
    Mar 2004
    Location
    SD
    Posts
    113

    Is there a way to make a form transparent?

    I want to know if tou can make a form transparent, but not all the stuff in.

    so you can see comboboxes, check boxes, list, exc.. with out a backround

    Thanks
    [Vbcode]If YourOpinion = WindowsIsCrap Then
    Kill Wndows
    Open Linux
    ElseIf YourOpinion = WindowsIsGreat Then
    Unload Me
    Else
    Get MSNTV
    End If[/vbcode]

  2. #2
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989
    www.planetsourcecode.com is a miracle...... just do a search and you will find a lot of crap (good crap...or stuff) there.....including what you need.....

  3. #3
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    Good stuff here at the vbForums too. I came accross exactly what
    you are looking for a while ago here. Search and i know you will
    find it.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  4. #4
    Fanatic Member doofusboy's Avatar
    Join Date
    Apr 2003
    Posts
    526
    Start a Project, add a textbox and 2 buttons, then copy/paste this code. The background of the form will be transparent and only the 3 controls will be visible.

    VB Code:
    1. Option Explicit
    2. Private Declare Function CreateRectRgn Lib _
    3.     "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, _
    4.     ByVal X2 As Long, ByVal Y2 As Long) As Long
    5. Private Declare Function CombineRgn Lib _
    6.     "gdi32" (ByVal hDestRgn As Long, ByVal hSrcRgn1 As Long, _
    7.     ByVal hSrcRgn2 As Long, ByVal nCombineMode As Long) As Long
    8. Private Declare Function SetWindowRgn Lib _
    9.     "user32" (ByVal hWnd As Long, ByVal hRgn As Long, _
    10.     ByVal bRedraw As Boolean) As Long
    11. Private Declare Function DeleteObject Lib _
    12.     "gdi32" (ByVal hObject As Long) As Long
    13.  
    14. ' Constants used by the CombineRgn function
    15. Private Const RGN_AND = 1
    16. Private Const RGN_OR = 2
    17. Private Const RGN_XOR = 3
    18. Private Const RGN_DIFF = 4
    19. Private Const RGN_COPY = 5
    20.  
    21. Private Sub Form_Activate()
    22.     Dim rgnForm As Long, rgnCombined As Long
    23.     Dim rgnControl As Long, x As Long
    24.     Dim formWidth As Single, formHeight As Single
    25.     Dim borderWidth As Single, titleHeight As Single
    26.     Dim ctlLeft As Single, ctlTop As Single
    27.     Dim ctlWidth As Single, ctlHeight As Single
    28.     Dim ctl As Control
    29.  
    30.     ' Calculate the form area
    31.     borderWidth = (Me.Width - Me.ScaleWidth) / 2
    32.     titleHeight = Me.Height - Me.ScaleHeight - borderWidth
    33.     ' Convert to Pixels
    34.     borderWidth = ScaleX(borderWidth, vbTwips, vbPixels)
    35.     titleHeight = ScaleY(titleHeight, vbTwips, vbPixels)
    36.     formWidth = ScaleX(Me.Width, vbTwips, vbPixels)
    37.     formHeight = ScaleY(Me.Height, vbTwips, vbPixels)
    38.    
    39.     ' Create a region for the whole form
    40.     rgnForm = CreateRectRgn(0, 0, formWidth, formHeight)
    41.    
    42.     rgnCombined = CreateRectRgn(0, 0, 0, 0)
    43.     ' Make the graphical area transparent by combining the two regions
    44.     x = CombineRgn(rgnCombined, rgnForm, rgnForm, RGN_DIFF)
    45.  
    46.     ' Make the controls visible
    47.     For Each ctl In Controls
    48.         ' Make the regions of controls whose container is the form visible
    49.         If TypeOf ctl.Container Is Form Then
    50.             ctlLeft = ScaleX(ctl.Left, vbTwips, vbPixels) + borderWidth
    51.             ctlTop = ScaleX(ctl.Top, vbTwips, vbPixels) + titleHeight
    52.             ctlWidth = ScaleX(ctl.Width, vbTwips, vbPixels) + ctlLeft
    53.             ctlHeight = ScaleX(ctl.Height, vbTwips, vbPixels) + ctlTop
    54.             rgnControl = CreateRectRgn(ctlLeft, ctlTop, ctlWidth, ctlHeight)
    55.             x = CombineRgn(rgnCombined, rgnCombined, rgnControl, RGN_OR)
    56.         End If
    57.     Next ctl
    58.    
    59.  
    60.     ' Set the clipping area of the window using the resulting region
    61.     SetWindowRgn hWnd, rgnCombined, True
    62.     ' Tidy up
    63.     x = DeleteObject(rgnCombined)
    64.     x = DeleteObject(rgnControl)
    65.     x = DeleteObject(rgnForm)
    66. End Sub
    67. Private Sub Command2_Click()
    68. Unload Me
    69. End Sub
    Do canibals not eat clowns because they taste funny?

  5. #5
    Fanatic Member
    Join Date
    Dec 2002
    Location
    North Carolina
    Posts
    734
    VB Code:
    1. Const LWA_COLORKEY = &H1
    2. Const LWA_ALPHA = &H2
    3. Const GWL_EXSTYLE = (-20)
    4. Const WS_EX_LAYERED = &H80000
    5. Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long
    6. Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
    7. Private Declare Function SetLayeredWindowAttributes Lib "user32" (ByVal hWnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long
    8. Private Sub Form_Load()
    9.     'KPD-Team 2000
    10.     'URL: [url]http://www.allapi.net/[/url]
    11.     'E-Mail: [email][email protected][/email]
    12.     Dim Ret As Long
    13.     'Set the window style to 'Layered'
    14.     Ret = GetWindowLong(Me.hWnd, GWL_EXSTYLE)
    15.     Ret = Ret Or WS_EX_LAYERED
    16.     SetWindowLong Me.hWnd, GWL_EXSTYLE, Ret
    17.     'Set the opacity of the layered window to 128
    18.     SetLayeredWindowAttributes Me.hWnd, 0, 128, LWA_ALPHA
    19. End Sub

    Only works in 2000 and above though.

  6. #6

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