Jump to content
Sign in to follow this  
HockeyFan

Create a CheckBox that is "ReadOnly"

Recommended Posts

HockeyFan

Is is possible to create a CheckBox that is "Read Only" but not disabled? ;)

I do not want the user to change its state, but be able to see that its been checked or unchecked.

Using GuiCtrlSetState($CheckBox1,$GUI_DISABLE) is not the desired outcome. :)

Thanks in advance.

Share this post


Link to post
Share on other sites
smartee

Try this :)

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

#region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 301, 97, 225, 219)
$Checkbox1 = GUICtrlCreateCheckbox("Check Me", 20, 10, 251, 31)
GUICtrlSetState(-1, $GUI_UNCHECKED)
$Checkbox2 = GUICtrlCreateCheckbox("Uncheck Me", 20, 50, 251, 31)
GUICtrlSetState(-1, $GUI_CHECKED)
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Checkbox1
            GUICtrlSetState($Checkbox1, $GUI_UNCHECKED)
        Case $Checkbox2
            GUICtrlSetState($Checkbox2, $GUI_CHECKED)
    EndSwitch
WEnd

Share this post


Link to post
Share on other sites
Spiff59

You could also hide the checkbox under another control such as a blank label:

#include <GUIConstantsEx.au3>

$Form1 = GUICreate("Form1", 301, 97, 225, 219)

GUICtrlCreateLabel("", 20, 20, 200, 16)
$Checkbox1 = GUICtrlCreateCheckbox("Check Me", 20, 20, 200, 16)
GUICtrlSetState(-1, $GUI_UNCHECKED)

GUICtrlCreateLabel("", 20, 50, 200, 16)
$Checkbox2 = GUICtrlCreateCheckbox("Uncheck Me", 20, 50, 200, 16)
GUICtrlSetState(-1, $GUI_CHECKED)

GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Share this post


Link to post
Share on other sites
HockeyFan

You could also hide the checkbox under another control such as a blank label:

#include <GUIConstantsEx.au3>

$Form1 = GUICreate("Form1", 301, 97, 225, 219)

GUICtrlCreateLabel("", 20, 20, 200, 16)
$Checkbox1 = GUICtrlCreateCheckbox("Check Me", 20, 20, 200, 16)
GUICtrlSetState(-1, $GUI_UNCHECKED)

GUICtrlCreateLabel("", 20, 50, 200, 16)
$Checkbox2 = GUICtrlCreateCheckbox("Uncheck Me", 20, 50, 200, 16)
GUICtrlSetState(-1, $GUI_CHECKED)

GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Spiff59,

Hmmmm...very interesting. Not the difficult solution I thought I would find, but provides the outcome of which I desire. :)

This makes it very simple to code. Thank you! ;)

HockeyFan

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.