Sign in to follow this  
Followers 0
Queener

checkbox as radio

5 posts in this topic

I'm trying to code if checkbox1 is checked, uncheck the rest of the checkbox (In another word, act as radio type). Here's what I come up, but didn't work:

$cdef1 = GUICtrlCreateCheckbox("Set Default",354,20,309,20,-1,-1)
GUICtrlSetFont(-1,12,400,0,"MS Sans Serif")
GUICtrlSetOnEvent($cdef1, "Checkbox2Click1")
$cdef2 = GUICtrlCreateCheckbox("Set Default",354,70,309,20,-1,-1)
GUICtrlSetFont(-1,12,400,0,"MS Sans Serif")
GUICtrlSetOnEvent($cdef2, "Checkbox2Click2")
$cdef3 = GUICtrlCreateCheckbox("Set Default",354,119,309,20,-1,-1)
GUICtrlSetFont(-1,12,400,0,"MS Sans Serif")
GUICtrlSetOnEvent($cdef3, "Checkbox2Click3")
$cdef4 = GUICtrlCreateCheckbox("Set Default",354,170,309,20,-1,-1)
GUICtrlSetFont(-1,12,400,0,"MS Sans Serif")
GUICtrlSetOnEvent($cdef4, "Checkbox2Click4")
 
Func Checkbox2Click1()
GUICtrlSetState($cdef2, $GUI_UNCHECKED)
GUICtrlSetState($cdef3, $GUI_UNCHECKED)
GUICtrlSetState($cdef4, $GUI_UNCHECKED)
GUICtrlSetState($chall, $GUI_UNCHECKED)
Return
EndFunc
 

 


Msgbox(0, "Hate", "Just hate it when I post a question and find my own answer after a couple tries. But if I don't post the question, I can't seem to resolve it at all.")

Share this post


Link to post
Share on other sites



What didn't work? It didn't run the function, or it didn't uncheck the other checkboxes? Are you using OnEvent mode in your script (Opt("GUIOnEventMode", 1))?


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

This sample does what you are trying to do ....

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 398, 170, 192, 132)
$Checkbox1 = GUICtrlCreateCheckbox("Checkbox1", 64, 40, 97, 17)
$Checkbox2 = GUICtrlCreateCheckbox("Checkbox2", 64, 72, 97, 17)
$Checkbox3 = GUICtrlCreateCheckbox("Checkbox3", 64, 104, 97, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###


func _uncheck()

    if guictrlread($Checkbox1)=$GUI_CHECKED then
            guictrlsetstate($Checkbox2,$GUI_UNCHECKED)
            guictrlsetstate($Checkbox3,$GUI_UNCHECKED)
    EndIf
EndFunc

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

        Case $Checkbox1
            _uncheck()
        Case $Checkbox2
        Case $Checkbox3
    EndSwitch
WEnd

Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt

Share this post


Link to post
Share on other sites

Try this:

#include <GUIConstantsEx.au3>
Opt("GUIOnEventMode", 1)

Global $aCheckboxes[4], $iBits = 0

$hGUI = GUICreate("Test", 600, 200)
$aCheckboxes[0] = GUICtrlCreateCheckbox("Set Default",354,20,309,20,-1,-1)
GUICtrlSetFont(-1,12,400,0,"MS Sans Serif")
GUICtrlSetOnEvent($aCheckboxes[0], "Checkbox2Click0")
$aCheckboxes[1] = GUICtrlCreateCheckbox("Set Default",354,70,309,20,-1,-1)
GUICtrlSetFont(-1,12,400,0,"MS Sans Serif")
GUICtrlSetOnEvent($aCheckboxes[1], "Checkbox2Click1")
$aCheckboxes[2] = GUICtrlCreateCheckbox("Set Default",354,119,309,20,-1,-1)
GUICtrlSetFont(-1,12,400,0,"MS Sans Serif")
GUICtrlSetOnEvent($aCheckboxes[2], "Checkbox2Click2")
$aCheckboxes[3] = GUICtrlCreateCheckbox("Set Default",354,170,309,20,-1,-1)
GUICtrlSetFont(-1,12,400,0,"MS Sans Serif")
GUICtrlSetOnEvent($aCheckboxes[3], "Checkbox2Click3")
GUISetState()
SetCheckboxStatus()

GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")

Do
Until Not Sleep(1000)

Func Checkbox2Click0()
    $iBits = 0
    SetCheckboxStatus()
EndFunc

Func Checkbox2Click1()
    $iBits = 1
    SetCheckboxStatus()
EndFunc

Func Checkbox2Click2()
    $iBits = 2
    SetCheckboxStatus()
EndFunc

Func Checkbox2Click3()
    $iBits = 3
    SetCheckboxStatus()
EndFunc

Func SetCheckboxStatus()
    ConsoleWrite($iBits & @CRLF)
    For $i = 0 To UBound($aCheckboxes) - 1
        If $i = $iBits Then
            GUICtrlSetState($aCheckboxes[$i], $GUI_CHECKED)
        Else
            GUICtrlSetState($aCheckboxes[$i], $GUI_UNCHECKED)
        EndIf
    Next
EndFunc

Func _Exit()
    GUIDelete()
    Exit
EndFunc

Br,

UEZ


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

What didn't work? It didn't run the function, or it didn't uncheck the other checkboxes? Are you using OnEvent mode in your script (Opt("GUIOnEventMode", 1))?

 

that simply does the trick. Forgot all about it...

I also notice that if this is activated, the switch case does not work.

Edited by asianqueen

Msgbox(0, "Hate", "Just hate it when I post a question and find my own answer after a couple tries. But if I don't post the question, I can't seem to resolve it at all.")

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  
Followers 0