Home > Visual Basic 6 > Membuat Form Transparan Visual Basic (2)

Membuat Form Transparan Visual Basic (2)

Source code berikut untuk membuat form yang transparan. Komponen-komponen yang ada di dalam form nya pun ikut transparan. Tingkat transparan bisa ditentukan sendiri seberapa transparan form yang akan dibuat.

Buat 1 project dengan :
1 Form
1 Module
1 TextBox
1 CommandButton

Copy source code berikut pada Module :

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 UpdateLayeredWindow Lib "user32" (ByVal hWnd As Long, ByVal hdcDst As Long, pptDst As Any, psize As Any, ByVal hdcSrc As Long, pptSrc As Any, crKey As Long, ByVal pblend As Long, 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 LWA_COLORKEY = &H1
Private Const LWA_ALPHA = &H2
Private Const ULW_COLORKEY = &H1
Private Const ULW_ALPHA = &H2
Private Const ULW_OPAQUE = &H4
Private Const WS_EX_LAYERED = &H80000

Public Function isTransparent(ByVal hWnd As Long) As Boolean
On Error Resume Next
Dim Msg As Long
Msg = GetWindowLong(hWnd, GWL_EXSTYLE)
If (Msg And WS_EX_LAYERED) = WS_EX_LAYERED Then
  isTransparent = True
Else
  isTransparent = False
End If
If Err Then
  isTransparent = False
End If
End Function

Public Function MakeTransparent(ByVal hWnd As Long, Perc As Integer) As Long
Dim Msg As Long
On Error Resume Next
If Perc < 0 Or Perc > 255 Then
  MakeTransparent = 1
Else
  Msg = GetWindowLong(hWnd, GWL_EXSTYLE)
  Msg = Msg Or WS_EX_LAYERED
  SetWindowLong hWnd, GWL_EXSTYLE, Msg
  SetLayeredWindowAttributes hWnd, 0, Perc, LWA_ALPHA
  MakeTransparent = 0
End If
If Err Then
  MakeTransparent = 2
End If
End Function

Public Function MakeOpaque(ByVal hWnd As Long) As Long
Dim Msg As Long
On Error Resume Next
Msg = GetWindowLong(hWnd, GWL_EXSTYLE)
Msg = Msg And Not WS_EX_LAYERED
SetWindowLong hWnd, GWL_EXSTYLE, Msg
SetLayeredWindowAttributes hWnd, 0, 0, LWA_ALPHA
MakeOpaque = 0
If Err Then
  MakeOpaque = 2
End If
End Function

Source code pada Form :

Private Sub Form_Load()
MakeTransparent Me.hWnd, 100 'ubah nilainya untuk mengatur tingkat
                             'ke-transparan-annya. range (0-255)
                             '0 form akan menghilang total
                             '255 form akan normal / terlihat jelas
End Sub

Untuk lebih jelasnya, download source code :


Referensi :

http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=8015&lngWId=1

About these ads
  1. rendy
    April 28, 2010 at 9:54 am | #1

    sekarang masalahnya kalo ada file image png yang backnya transparant gimana caranya? saya pernah bikin tapi lupa dah lama ga make vb6 :p jadi kaya startupnya adobe reader ato yang lainnya :)

  2. October 25, 2010 at 10:58 am | #2

    mas irfan ad sourse kode membuat mp3 player ???

  3. tria
    November 8, 2011 at 7:26 am | #3

    mas irfan tolong bantu aq mas, gmn cara import dari ecxel ke Access, tolong dibalas za, atau dikirim ke mailq, mksih

  4. December 16, 2012 at 10:12 am | #4

    Excellent article on using this website. Thank you so much.

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 136 other followers

%d bloggers like this: