Transparent Form Background w/Labels

Justin-Credible
02-03-2005, 05:18 PM
I'm using the following code to make my form background transparent.

The form goes transparent, but I can't get the label's background to be transparent. They always take the color of the form, which is grey. I've tried setting the label's backstyle to "0 - Transparent"


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 Boolean) As Long
Private Declare Function DeleteObject Lib _
"gdi32" (ByVal hObject As Long) As Long
' Constants used by the CombineRgn function
Private Const RGN_AND = 1
Private Const RGN_OR = 2
Private Const RGN_XOR = 3
Private Const RGN_DIFF = 4
Private Const RGN_COPY = 5

Private Sub Form_Activate()
Dim rgnForm As Long, rgnCombined As Long
Dim rgnControl As Long, x As Long
Dim formWidth As Single, formHeight As Single
Dim borderWidth As Single, titleHeight As Single
Dim ctlLeft As Single, ctlTop As Single
Dim ctlWidth As Single, ctlHeight As Single
Dim ctl As Control
' Calculate the form area
borderWidth = (Me.Width - Me.ScaleWidth) / 2
titleHeight = Me.Height - Me.ScaleHeight - borderWidth
' Convert to Pixels
borderWidth = ScaleX(borderWidth, vbTwips, vbPixels)
titleHeight = ScaleY(titleHeight, vbTwips, vbPixels)
formWidth = ScaleX(Me.Width, vbTwips, vbPixels)
formHeight = ScaleY(Me.Height, vbTwips, vbPixels)
' Create a region for the whole form
rgnForm = CreateRectRgn(0, 0, formWidth, formHeight)
rgnCombined = CreateRectRgn(0, 0, 0, 0)
' Make the graphical area transparent by combining the two regions
x = CombineRgn(rgnCombined, rgnForm, rgnForm, RGN_DIFF)
' Make the controls visible
For Each ctl In Controls
' Make the regions of controls whose container is the form visible
If TypeOf ctl.Container Is Form Then
ctlLeft = ScaleX(ctl.Left, vbTwips, vbPixels) + borderWidth
ctlTop = ScaleX(ctl.Top, vbTwips, vbPixels) + titleHeight
ctlWidth = ScaleX(ctl.Width, vbTwips, vbPixels) + ctlLeft
ctlHeight = ScaleX(ctl.Height, vbTwips, vbPixels) + ctlTop
rgnControl = CreateRectRgn(ctlLeft, ctlTop, ctlWidth, ctlHeight)
x = CombineRgn(rgnCombined, rgnCombined, rgnControl, RGN_OR)
End If
Next ctl
' Set the clipping area of the window using the resulting region
SetWindowRgn hWnd, rgnCombined, True
' Tidy up
x = DeleteObject(rgnCombined)
x = DeleteObject(rgnControl)
x = DeleteObject(rgnForm)
End Sub

ellebanna
02-04-2005, 12:06 PM
When you set the backstyle of the label transparent, the label appears to be transparent. The Backcolor however defaults to something and in this case a shade of gray which is something you cannot remove, you can change it but when you run your application and the label style is set to transparent it will appear to be transparent against the form.

Justin-Credible
02-04-2005, 02:00 PM
So there is no way to display some text on the screen that has no color behind it?

RayOK
02-04-2005, 05:27 PM
Just saw this while searching for something else and reminded me of your post.. :D Taken from this (http://www.codeguru.com/vb/gen/vb_graphics/) page..

Fast Transparency (http://www.codeguru.com/vb/gen/vb_graphics/transparency/article.php/c5329/)
Creating Translucent/Transparent Windows in VB (1) (http://www.codeguru.com/vb/gen/vb_graphics/transparency/article.php/c6979/)
[Updated] Creating Translucent/Transparent Windows in VB (2) (http://www.codeguru.com/vb/gen/vb_graphics/transparency/article.php/c6981/)

Justin-Credible
02-09-2005, 06:13 PM
Thats what I needed! Thanks.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum