On Fri, 2 Jan 2004 10:56:02 +0100, "Henrik"
<ds*******@vip.cybercity.dk> wrote:
Hi
how can i make the backcolor of a form transparent
Here is some code that someone posted some time ago
- followed by another demo
Notice the MouseMove
- it shows that, although transparent, it is still 'on top'
The second Demo produces a 'shaped' Form
- that does _not_ get the mouse events in the transparent area
Option Explicit
Private Declare Function SetWindowLong _
Lib "user32" Alias "SetWindowLongA" ( _
ByVal hwnd As Long, _
ByVal nIndex As Long, _
ByVal dwNewLong As Long) As Long
Private Const GWL_EXSTYLE = (-20)
Private Const WS_EX_TRANSPARENT = &H20&
Public Sub MakeTransparent(frmIn As Form)
' Comments : Sets the form's style to be transparent. This call
should
' be made before the form is shown, for example in the
Load
' event
' Parameters: frmIn - form to modify
' Returns : Nothing
' Source : Total VB SourceBook 6
'
Dim lngResult As Long
On Error GoTo PROC_ERR
lngResult = SetWindowLong(frmIn.hwnd, _
GWL_EXSTYLE, _
WS_EX_TRANSPARENT)
PROC_EXIT:
Exit Sub
PROC_ERR:
MsgBox "Error: " & Err.Number & ". " & Err.Description, , _
"MakeTransparent"
Resume PROC_EXIT
End Sub
Private Sub Form_Load()
Call MakeTransparent(Me)
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As
Single, Y As Single)
MsgBox "Mouse Move"
End Sub
====== SECOND EXAMPLES =====
Option Explicit
' from Mike Williams
Private Declare Function CreateEllipticRgn _
Lib "gdi32" ( _
ByVal X1 As Long, _
ByVal Y1 As Long, _
ByVal x2 As Long, _
ByVal y2 As Long _
) As Long
Private Declare Function SetWindowRgn _
Lib "user32" ( _
ByVal hWnd As Long, _
ByVal hRgn As Long, _
ByVal bRedraw As Long _
) As Long
Sub MakeMeRound(TheControl As Object)
Dim hRegion As Long, lResult As Long
TheControl.Height = TheControl.Width
hRegion = CreateEllipticRgn(0, 0, TheControl.Width \ _
Screen.TwipsPerPixelX, TheControl.Height \ _
Screen.TwipsPerPixelY)
lResult = SetWindowRgn(TheControl.hWnd, hRegion, True)
End Sub
Private Sub Command1_Click()
MakeMeRound Me
End Sub