Wednesday, July 28, 2010

To set Form Opacity on VB6 code

Setting transparan form dengan VB6.
It’s different from VB.Net that have form property “Opacity” from value 0 – 100 %.

image

For Visual basic 6 we must set from code behind like this :
1. Set new module (file .bas)

Private Declare Function GetWindowLongA Lib "user32" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLongA Lib "user32" (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 crey As Byte, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long
Private Const GWL_EXSTYLE = (-20)
Private Const WS_EX_LAYERED = &H80000
Private Const LWA_ALPHA = &H2&
Public Function Opacity(Value As Byte, Frm As Form)
On Error GoTo ErrorHandler
    Dim MaxVal As Byte, MinVal As Byte
    MinVal = 20: MaxVal = 255
    If Value > MaxVal Then Value = MaxVal
    If Value < MinVal Then Value = MinVal
    SetWindowLongA Frm.hwnd, GWL_EXSTYLE, GetWindowLongA(Frm.hwnd, GWL_EXSTYLE) Or WS_EX_LAYERED
    SetLayeredWindowAttributes Frm.hwnd, 0, Value, LWA_ALPHA
ErrorHandler:     Exit Function
End Function




2. Set on form code when load (file .frm)



Private Sub Form_Load()
    Opacity 150, Me
End Sub





3 comments:

Unknown said...

Thank You So Much About That So Useful Example

Deddy Hartanto said...

Ok, your welcome. See you again in my other post.

Abdul bari said...

Opacity Meter. Davinor TOM11 is a modern opacity and transmission meter optimized for thin materials like plastic films opacity meter, sheets and papers.

Hukum Tabur Tuai

Ingatlah hukum dasar ini, dalam kehidupanmu  Barang siapa yang menanam, dia pula yang akan menuai