Hello,
I'm trying to find an API that LOCKS a checkbox in VB. There isn't a Locked property for the checkbox but I've heard it can be done. Any ideas?
Printable View
Hello,
I'm trying to find an API that LOCKS a checkbox in VB. There isn't a Locked property for the checkbox but I've heard it can be done. Any ideas?
Why not disable the box? Use the Enabled property.
Hi
Yeah u beat me to same conclusion Midgets. Or maybe this is another attempt at changing the standard operation of a checkbox to confuse users? :p
Regards
Stuart
Changing the enabled property will cause the checkbox to be grayed. I want it to be enabled but that it's value will be locked.
Ok
if u dont end up going API way u can always simply have a very small checkbox with no caption and an attached label control that doubles as the checkbox caption. U can add code to the Label click event to change the checkbox value when 'enabled' and to ignore the checkbox value when 'disabled'
Regards
Stuart
Use this to drive your users nuts.
VB Code:
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_AUTOCHECKBOX = 1 ' Make a checkbox control read-only (or restore its ' regular behavior). ' Doesn't work well if the Style property is set to 1-Graphical Sub MakeCheckBoxReadOnly(CheckBox As CheckBox, ByVal bReadOnly As Boolean) Dim lStyle As Long lStyle = GetWindowLong(CheckBox.hWnd, GWL_STYLE) If bReadOnly Then lStyle = lStyle Or BS_AUTOCHECKBOX Else lStyle = lStyle And (Not BS_AUTOCHECKBOX) End If SetWindowLong CheckBox.hWnd, GWL_STYLE, lStyle End Sub Private Sub Command1_Click() Static b As Boolean Call MakeCheckBoxReadOnly(Check1, b) b = Not b End Sub
Couldn't you just use the LockWindowUpdate API call ?