Senin, 06 Februari 2017

Cara Membuat Form Transparan di VB6

Tags
Cara Membuat Form Transparan di VB6

Selamat datang di artikel ini, disini kita akan belajar bagaimana membuat form transparan, hal ini untuk memper indah tampilan yang sudah ada, dan langsung saja kita mencobanya silahkan ikuti langkah-langkah berikut:
- Buka VB6 nya buat sebuah form dengan rincian:
- Masukan Sebuah Image dan masukan gambar gambar gif yang gambarnya transparan.
- Buat Sebuah Modul dan masukan script di bawah ini:

Option Explicit
Public Const LWA_COLORKEY = 1
Public Const LWA_ALPHA = 2
Public Const LWA_BOTH = 3
Public Const WS_EX_LAYERED = &H80000
Public Const GWL_EXSTYLE = -20
Public Declare Function SetLayeredWindowAttributes Lib "user32" (ByVal hwnd As Long, ByVal warna As Long, ByVal x As Byte, ByVal Alpha As Long) As Boolean
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Sub SetTransparan(frm As Long, warna As Long, nTrans As Integer, flag As Byte)
On Error GoTo Err
Dim attrib As Long
attrib = GetWindowLong(frm, GWL_EXSTYLE)
SetWindowLong frm, GWL_EXSTYLE, attrib Or WS_EX_LAYERED
SetLayeredWindowAttributes frm, warna, nTrans, flag
Exit Sub
Err:
MsgBox Err.Description & " Source : " & Err.Source
End Sub
- Masukan Pula pada Form sintak berikut:
Private Declare Function ReleaseCapture Lib "user32.dll" () As Long 'untuk menggerakkan form’
Private Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Const HTCAPTION As Integer = 2
Private Const WM_NCLBUTTONDOWN As Integer = &HA1
Option Explicit
Dim Color As Long, flag As Byte
Private Sub Form_Activate()
On Error GoTo Err
Color = vbBlue
flag = flag Or LWA_COLORKEY
SetTransparan Form_login1.hwnd, Color, 0, flag
Exit Sub
Err:
MsgBox Err.Description & " Source : " & Err.Source
End Sub
Private Sub Image1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
ReleaseCapture
If Button = 1 Then
SendMessage Me.hwnd, WM_NCLBUTTONDOWN, HTCAPTION, 0
End If
End Sub


- Setelah itu jalankan programnya

sumber: belajardasarvisualbasic.blogspot.co.id/