|
Изменение свойства Style (стиль) |
|
|
Если вы попытаетесь изменить свойство Style элементов OptionButton и CheckBox во время выполнения программы, вы получите сообщение об ошибке "can't assign to read-only property". Для решения этой проблемы вы можете воспользоваться следующим кодом. Добавьте на форму элементы OptionButton, CheckBox и 3 CommandButton. 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
Const GWL_STYLE = (-16)
Const BS_PUSHLIKE = &H1000&
Public Sub SetGraphicStyle(StyleButton As Control, Flag As Boolean)
Dim curstyle As Long
Dim newstyle As Long
'exit this sub if the control is not Option Button or Check Box
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
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
Private Sub Command3_Click()
Option1.Value = False
Check1.Value = False
End Sub
|
|
|
|
|
|
|