Results 1 to 9 of 9

Thread: Transparent forms! HELLLLLPPPPP!!!

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2001
    Location
    England
    Posts
    8

    Angry Transparent forms! HELLLLLPPPPP!!!

    Grrrrrrrr!!!!!

    For some reason I can't make my form become transparent!

    I am in the middle of creating an MP3 player and want a realistic style! I want to have a trasparent FORM!!

    Is there some way I can do this because, quite honestly, VB5 help is pretty crap.

    Bruta

    _________________
    One today is worth two tomorrow

  2. #2
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827
    Try this:

    VB Code:
    1. Option Explicit
    2. Private Declare Function CreateRectRgn Lib "gdi32" (ByVal X1 As Long, _
    3. ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
    4. Private Declare Function CombineRgn Lib "gdi32" (ByVal hDestRgn As _
    5. Long, ByVal hSrcRgn1 As Long, ByVal hSrcRgn2 As Long, ByVal _
    6. nCombineMode As Long) As Long
    7. Private Declare Function SetWindowRgn Lib "user32" (ByVal hWnd As _
    8. Long, ByVal hRgn As Long, ByVal bRedraw As Long) As Long
    9.  
    10. Public Sub TransparentForm(frm As Form)
    11.     frm.ScaleMode = vbPixels
    12.     Const RGN_DIFF = 4
    13.     Const RGN_OR = 2
    14.  
    15.     Dim outer_rgn As Long
    16.     Dim inner_rgn As Long
    17.     Dim wid As Single
    18.     Dim hgt As Single
    19.     Dim border_width As Single
    20.     Dim title_height As Single
    21.     Dim ctl_left As Single
    22.     Dim ctl_top As Single
    23.     Dim ctl_right As Single
    24.     Dim ctl_bottom As Single
    25.     Dim control_rgn As Long
    26.     Dim combined_rgn As Long
    27.     Dim ctl As Control
    28.  
    29.     If frm.WindowState = vbMinimized Then Exit Sub
    30.  
    31.     ' Create the main form region.
    32.     wid = frm.ScaleX(frm.Width, vbTwips, vbPixels)
    33.     hgt = frm.ScaleY(frm.Height, vbTwips, vbPixels)
    34.     outer_rgn = CreateRectRgn(0, 0, wid, hgt)
    35.  
    36.     border_width = (wid - frm.ScaleWidth) / 2
    37.     title_height = hgt - border_width - frm.ScaleHeight
    38.     inner_rgn = CreateRectRgn(border_width, title_height, wid - border_width, _
    39.         hgt - border_width)
    40.  
    41.     ' Subtract the inner region from the outer.
    42.     combined_rgn = CreateRectRgn(0, 0, 0, 0)
    43.     CombineRgn combined_rgn, outer_rgn, inner_rgn, RGN_DIFF
    44.  
    45.     ' Create the control regions.
    46.     For Each ctl In frm.Controls
    47.         If ctl.Container Is frm Then
    48.             ctl_left = frm.ScaleX(ctl.Left, frm.ScaleMode, vbPixels) _
    49.                 + border_width
    50.             ctl_top = frm.ScaleX(ctl.Top, frm.ScaleMode, vbPixels) + title_height
    51.             ctl_right = frm.ScaleX(ctl.Width, frm.ScaleMode, vbPixels) + ctl_left
    52.             ctl_bottom = frm.ScaleX(ctl.Height, frm.ScaleMode, vbPixels) + ctl_top
    53.             control_rgn = CreateRectRgn(ctl_left, ctl_top, ctl_right, ctl_bottom)
    54.             CombineRgn combined_rgn, combined_rgn, control_rgn, RGN_OR
    55.         End If
    56.     Next ctl
    57.  
    58.     'Restrict the window to the region.
    59.     SetWindowRgn frm.hWnd, combined_rgn, True
    60. End Sub
    61.  
    62. Private Sub Form_Resize()
    63.     TransparentForm Me
    64. End Sub
    Baaaaaaaaah

  3. #3
    Addicted Member
    Join Date
    Feb 2001
    Location
    Classified
    Posts
    234
    whoa, thanks abdul !

    Ive been fiddling around with all kinds of API functions to get my whole form transperent. Couldent ever get it quite right.

    IT WORKS NOW
    My ICQ Status: (85634850)

    Seriously Sick Tshirts

  4. #4
    Lively Member Zero's Avatar
    Join Date
    Feb 2000
    Posts
    101

    Right...

    Normally, if you put a GIF with a transparent background in an image (not a picbox) control the background will be transparent on the form- You can see other controls through it. But if you do this on a form using your code, the once transparent GIF has a grey box around it.

    Do you know of a way to keep the GIF's background transparent when you make the form itself transparent? Is there a way at all?

    ~Zero the Inestimable

  5. #5
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827
    Sorry, I still did not get it:

    Do you want to put this gif(let us assume a circle) directly onto the form or Do you want to load the gif in a image box and then you want to show the image box on the transparent form?

    So basically, Do you want to, somehow, show the circle(gif) on the transparent form?
    Baaaaaaaaah

  6. #6
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    if you convert your gif file into ico format, it's automatically blitted transparently if you put it in a imagebox. If you want you could also use regions to your advantage, I made a control once that cuts out the regions specified by a userdefined color you use as mask. If you want I could upload it here.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  7. #7
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827
    What do you want to make the region of? If it is an image control then its is impossible. But if you just want to show a transparent picture then you can put that in a picture box, and then make the regions of picture box(you also need to make the form transparent and set its borderstyle to none)
    Baaaaaaaaah

  8. #8
    DaoK
    Guest
    abdul he ONLY want to put a background (exemple a picture of the letter "B" and he want all the background transparent but not the letter "B". But he want the inside of the "B" transparent (the "B" letter is saved in transparent Gif so he should be able to see inside the "B")

    I hope that gonna help you to understand him.

  9. #9
    Addicted Member Andreas@ALSoft's Avatar
    Join Date
    Jul 2001
    Location
    Germany
    Posts
    201

    Lightbulb

    I'm not sure but it should be possible to create a user control with a maskpicture and a background picture so that the regions around the background picture are transparent.
    Set the control's controlcontainer property to true
    Then place that control on your form you made transparent with abdul's code.
    I hope it works...

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