Saturday, October 25, 2014

Mengganti Warna Form Pada Visual Basic 6.0



Mengganti warna form ini fungsinya mungkin agar user tidak merasa jenuh dengan program yang dirancang, untuk caranya tambahkan sebuah command button atau pun menu pada form, dan buat captionnya menjadi Change Colour , dan masuk pada coding window dan ketikkan coding berikut :

Option Explicit
Public Enum CHOOSE_COLOR_FLAGS
CC_RGBINIT = &H1&
CC_FULLOPEN = &H2&
CC_PREVENTFULLOPEN = &H4&
CC_SHOWHELP = &H8&
CC_ENABLEHOOK = &H10&
CC_ENABLETEMPLATE = &H20&
CC_ENABLETEMPLATEHANDLE = &H40&
CC_SOLIDCOLOR = &H80&
CC_ANYCOLOR = &H100&
End Enum
 
Private Type CHOOSECOLOR
lStructSize As Long
hwndOwner As Long
hInstance As Long
rgbResult As Long
lpCustColors As Long
flags As CHOOSE_COLOR_FLAGS
lCustData As Long
lpfnHook As Long
lpTemplateName As String
End Type

Private Declare Function ChooseColor_API Lib "comdlg32.dll" Alias "ChooseColorA" (lpChoosecolor As CHOOSECOLOR) As Long

Private Sub Command1_Click()
Dim lpChoosecolor As CHOOSECOLOR
Dim aColorRef(15) As Long
 
With lpChoosecolor
.lStructSize = Len(lpChoosecolor)
.hwndOwner = hWnd
.rgbResult = Me.BackColor
.lpCustColors = VarPtr(aColorRef(0))
.flags = CC_SOLIDCOLOR Or CC_ANYCOLOR Or CC_RGBINIT
End With

If ChooseColor_API(lpChoosecolor) Then
BackColor = lpChoosecolor.rgbResult
End If
End Sub

Setelah itu jalankan program dengan menekan F5

Labels: ,

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home