Jump to content

Create a CheckBox that is "ReadOnly"


Recommended Posts

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.

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...