Error "Can't assign to read-only",Mengganti Style Option/CheckBox Saat Runtime VB6
Berikut ini adalah cara mengganti setting property Style pada Option/Checkbox pada saat runtime di visual basic 6. Jika Anda pernah mengganti setting property Style Option Button pada saat runtime, Anda pasti mendapat pesan error "Can't assign to read-only", untuk mempraktekannya siapkan :
1. Buat 1 Project baru dengan 1 Form, 1 OptionButton, 1 CheckBox, dan 2 Commandbutton.2. Copy-kan coding berikut ke editor Module/Form yang bertalian.
'--- Coding di Module...
Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" _
(ByVal hwnd As Long, ByVal nIndex As Long) As Long
Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
(ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public Const GWL_STYLE = (-16)
Public Const BS_PUSHLIKE = &H1000&
Public Sub SetGraphicStyle(StyleButton As Control, Flag As Boolean)
Dim curstyle As Long
Dim newstyle As Long
'Jika control bukan OptionButton atau CheckBox
If Not TypeOf StyleButton Is OptionButton And _
Not TypeOf StyleButton Is CheckBox Then Exit Sub
curstyle = GetWindowLong(StyleButton.hwnd, GWL_STYLE)
If Flag Then
curstyle = curstyle Or BS_PUSHLIKE
Else
curstyle = curstyle And (Not BS_PUSHLIKE)
End If
newstyle = SetWindowLong(StyleButton.hwnd, GWL_STYLE, curstyle)
StyleButton.Refresh
End Sub
'--- Batas coding di Module...
'--- Coding di Form...
Private Sub Command1_Click()
Call SetGraphicStyle(Option1, True)
Call SetGraphicStyle(Check1, True)
End Sub
Private Sub Command2_Click()
Call SetGraphicStyle(Option1, False)
Call SetGraphicStyle(Check1, False)
End Sub
'--- Batas coding di Form...
Tags:
contoh program vb6, contoh fungsi di vb6, cara penggunaan fungsi vb, tutorial vb6, download tutorial vb6, vb6 tutorial download, dasar dasar vb6, belajar vb6, cara mudah belajar vb6, vb6 artikel download, vb6 blog, contoh program vb6, artikel vb6, semua tentang vb6, vb6 api, cara menggunakan module, cara menggunakan class module
Posting Komentar untuk "Error "Can't assign to read-only",Mengganti Style Option/CheckBox Saat Runtime VB6"