Membuat Transparan Form

BY IN Visual Basic Comments Off on Membuat Transparan Form

Untuk membuat form bergaya transparan, yang perlu kita siapkan adalah
sebuah Form dengan Visible = False dan 2 Timer
dengan Intervalnya Masing2x = 100 dan Enabled-nya masing2x = False

Kemudian berikut adalah kode programnya

Option Explicit

Const LWA_BOTH = 3
Const LWA_ALPHA = 2
Const LWA_COLORKEY = 1
Const GWL_EXSTYLE = -20
Const WS_EX_LAYERED = &H80000

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 Declare Function SetLayeredWindowAttributes Lib “user32” _
(Byval hWnd As Long, Byval color As Long, Byval x As Byte, _
Byval alpha As Long) As Boolean
Dim Transparan As Integer

Sub Trans(hWnd As Long, T As Integer)
On Error Resume Next

Dim OK As Long
OK = GetWindowLong(hWnd, GWL_EXSTYLE)

SetWindowLong hWnd, GWL_EXSTYLE, OK Or WS_EX_LAYERED
SetLayeredWindowAttributes hWnd, RGB(255, 255, 0), T, LWA_ALPHA
Exit Sub

End Sub

Private Sub Form_Load()
Timer1.Enabled = True
End Sub

Private Sub Form_Unload(Cancel As Integer)
Cancel = 1
Timer1.Enabled = False
Timer2.Enabled = True
End Sub

Private Sub Timer1_Timer()
On Error Resume Next
Transparan = Transparan + 5
If Transparan > 255 Then Transparan = 255: Timer1.Enabled = False
Trans Me.hWnd, Transparan
Me.Show
End Sub

Private Sub Timer2_Timer()
On Error Resume Next
Transparan = Transparan – 5
If Transparan < 0 Then Transparan = 0: Timer2.Enabled = False: End
Transo Me.hWnd, Transparan
End Sub




Comments are closed.