|
-
Jul 29th, 2001, 11:23 AM
#1
Thread Starter
New Member
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
-
Jul 29th, 2001, 03:02 PM
#2
PowerPoster
Try this:
VB Code:
Option Explicit
Private Declare Function CreateRectRgn Lib "gdi32" (ByVal X1 As Long, _
ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Private Declare Function CombineRgn Lib "gdi32" (ByVal hDestRgn As _
Long, ByVal hSrcRgn1 As Long, ByVal hSrcRgn2 As Long, ByVal _
nCombineMode As Long) As Long
Private Declare Function SetWindowRgn Lib "user32" (ByVal hWnd As _
Long, ByVal hRgn As Long, ByVal bRedraw As Long) As Long
Public Sub TransparentForm(frm As Form)
frm.ScaleMode = vbPixels
Const RGN_DIFF = 4
Const RGN_OR = 2
Dim outer_rgn As Long
Dim inner_rgn As Long
Dim wid As Single
Dim hgt As Single
Dim border_width As Single
Dim title_height As Single
Dim ctl_left As Single
Dim ctl_top As Single
Dim ctl_right As Single
Dim ctl_bottom As Single
Dim control_rgn As Long
Dim combined_rgn As Long
Dim ctl As Control
If frm.WindowState = vbMinimized Then Exit Sub
' Create the main form region.
wid = frm.ScaleX(frm.Width, vbTwips, vbPixels)
hgt = frm.ScaleY(frm.Height, vbTwips, vbPixels)
outer_rgn = CreateRectRgn(0, 0, wid, hgt)
border_width = (wid - frm.ScaleWidth) / 2
title_height = hgt - border_width - frm.ScaleHeight
inner_rgn = CreateRectRgn(border_width, title_height, wid - border_width, _
hgt - border_width)
' Subtract the inner region from the outer.
combined_rgn = CreateRectRgn(0, 0, 0, 0)
CombineRgn combined_rgn, outer_rgn, inner_rgn, RGN_DIFF
' Create the control regions.
For Each ctl In frm.Controls
If ctl.Container Is frm Then
ctl_left = frm.ScaleX(ctl.Left, frm.ScaleMode, vbPixels) _
+ border_width
ctl_top = frm.ScaleX(ctl.Top, frm.ScaleMode, vbPixels) + title_height
ctl_right = frm.ScaleX(ctl.Width, frm.ScaleMode, vbPixels) + ctl_left
ctl_bottom = frm.ScaleX(ctl.Height, frm.ScaleMode, vbPixels) + ctl_top
control_rgn = CreateRectRgn(ctl_left, ctl_top, ctl_right, ctl_bottom)
CombineRgn combined_rgn, combined_rgn, control_rgn, RGN_OR
End If
Next ctl
'Restrict the window to the region.
SetWindowRgn frm.hWnd, combined_rgn, True
End Sub
Private Sub Form_Resize()
TransparentForm Me
End Sub
-
Jul 31st, 2001, 02:28 PM
#3
Addicted Member
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
-
Jul 31st, 2001, 02:53 PM
#4
Lively Member
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
-
Jul 31st, 2001, 03:51 PM
#5
PowerPoster
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?
-
Aug 1st, 2001, 03:55 PM
#6
transcendental analytic
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.
-
Aug 1st, 2001, 04:25 PM
#7
PowerPoster
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)
-
Aug 1st, 2001, 04:41 PM
#8
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.
-
Aug 1st, 2001, 04:52 PM
#9
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|