Hola,
Este sencillo código sirve para transparentar totalmente un color determiando ya sea del formulario o de un objeto cualquiera que esté dentro del formulario. He establecido la propiedad Backcolor del formulario a vbRed y por lo tanto toda la parte interna del formulario se verá transparente al 100%. He utilizado el Rojo pero puedes usar cualquier color.
Option Explicit
Private Declare Function SetLayeredWindowAttributes Lib "user32" (ByVal hwnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
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_LAYERED = &H80000
Public Function TransparentarColor(ByVal hwnd As Long, Color As Long) As Long
On Error Resume Next
SetWindowLong hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) Or WS_EX_LAYERED
SetLayeredWindowAttributes hwnd, Color, 0, &H1
End Function
Private Sub Form_Load()
Me.BackColor = vbRed
Call TransparentarColor(Me.hwnd, vbRed)
End Sub
Añado este código de más como muestra de la utilidad que tiene el código para crear formularios personalizados.
Option Explicit
'Mover formulario sin barra
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function ReleaseCapture Lib "user32" () As Long
Const WM_NCLBUTTONDOWN = &HA1
Const HTCAPTION = 2
Private Declare Function SetLayeredWindowAttributes Lib "user32" (ByVal hwnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
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_LAYERED = &H80000
Public Function TransparentarColor(ByVal hwnd As Long, Color As Long) As Long
On Error Resume Next
SetWindowLong hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) Or WS_EX_LAYERED
SetLayeredWindowAttributes hwnd, Color, 0, &H1
End Function
Private Sub Form_Load()
Me.BackColor = vbRed
Call TransparentarColor(Me.hwnd, vbRed)
End Sub
Private Sub Command1_Click()
Unload Me
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim Z As Long
If Button = 1 Then
ReleaseCapture
Z = SendMessage(Me.hwnd, WM_NCLBUTTONDOWN, HTCAPTION, 0)
End If
End Sub
Y el proyecto lo puedes descargar aquí.
Form_Personalized.zip