Jump to content

Check Box Question


Capone
 Share

Recommended Posts

how would i make one check box uncheck another/others if checked?

here's what i have

$GUI = GUICreate("Test", 364, 600)
$Box1 = GuiCtrlCreateCheckbox("", 0, 400, 80, 20)
GuiCtrlSetState(-1, $GUI_CHECKED)
$Box2 = GUICtrlCreateCheckbox("", 0, 430, 100, 20)
GUISetState(@SW_SHOW)

While 1
    GuiGetMsg($Normal)
    If $Box1 = $GUI_CHECKED Then
        GUISetState($Box2, $GUI_UNCHECKED)
    EndIf
    If $Box2 = $GUI_CHECKED Then
        GUISetState($Box1, $GUIUNCHECKED)
    EndIf
WEnd
Link to comment
Share on other sites

If I understand correctly, you want to have if one box is checked then other predefined boxes unchecked if checked.

$GUI = GUICreate("Test", 364, 600)
$Box1 = GuiCtrlCreateCheckbox("", 0, 400, 80, 20)
GuiCtrlSetState(-1, $GUI_CHECKED)
$Box2 = GUICtrlCreateCheckbox("", 0, 430, 100, 20)
GUISetState(@SW_SHOW)

While 1
    $msg = GuiGetMsg()
    Switch $msg
      Case $box1
        If $Box2 = $GUI_CHECKED Then
           GUISetState($Box2, $GUI_UNCHECKED)
        Else
           GUISetState($Box2, $GUI_CHECKED)
        EndIf
      Case $Box2
         If $Box1 = $GUI_CHECKED Then
           GUISetState($Box1, $GUI_UNCHECKED)
         Else
           GUISetState($Box1, $GUI_CHECKED)
         EndIf
    EndSwitch
WEnd
Triton
Link to comment
Share on other sites

If I understand correctly, you want to have if one box is checked then other predefined boxes unchecked if checked.

$GUI = GUICreate("Test", 364, 600)
$Box1 = GuiCtrlCreateCheckbox("", 0, 400, 80, 20)
GuiCtrlSetState(-1, $GUI_CHECKED)
$Box2 = GUICtrlCreateCheckbox("", 0, 430, 100, 20)
GUISetState(@SW_SHOW)

While 1
    $msg = GuiGetMsg()
    Switch $msg
      Case $box1
        If $Box2 = $GUI_CHECKED Then
           GUISetState($Box2, $GUI_UNCHECKED)
        Else
           GUISetState($Box2, $GUI_CHECKED)
        EndIf
      Case $Box2
         If $Box1 = $GUI_CHECKED Then
           GUISetState($Box1, $GUI_UNCHECKED)
         Else
           GUISetState($Box1, $GUI_CHECKED)
         EndIf
    EndSwitch
WEnd

i tried your idea and it didnt work properly but i see what your trying to do

Link to comment
Share on other sites

Capone

Example:

#include <GuiConstantsEx.au3>

$GUI = GUICreate("Test", 364, 600)

$Box1 = GuiCtrlCreateCheckbox("", 0, 400, 80, 20)
GuiCtrlSetState(-1, $GUI_CHECKED)

$Box2 = GUICtrlCreateCheckbox("", 0, 430, 100, 20)

GUISetState(@SW_SHOW)

While 1
    $msg = GuiGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            Exit
      Case $box1
        If GUICtrlRead($Box2) = $GUI_CHECKED Then
            GUICtrlSetState($Box2, $GUI_UNCHECKED)
        Else
            GUICtrlSetState($Box2, $GUI_CHECKED)
        EndIf
    Case $Box2
        If GUICtrlRead($Box1) = $GUI_CHECKED Then
            GUICtrlSetState($Box1, $GUI_UNCHECKED)
        Else
            GUICtrlSetState($Box1, $GUI_CHECKED)
        EndIf
    EndSwitch
WEnd
Edited by rasim
Link to comment
Share on other sites

Capone

Example:

#include <GuiConstantsEx.au3>

$GUI = GUICreate("Test", 364, 600)

$Box1 = GuiCtrlCreateCheckbox("", 0, 400, 80, 20)
GuiCtrlSetState(-1, $GUI_CHECKED)

$Box2 = GUICtrlCreateCheckbox("", 0, 430, 100, 20)

GUISetState(@SW_SHOW)

While 1
    $msg = GuiGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            Exit
      Case $box1
        If GUICtrlRead($Box2) = $GUI_CHECKED Then
            GUICtrlSetState($Box2, $GUI_UNCHECKED)
        Else
            GUICtrlSetState($Box2, $GUI_CHECKED)
        EndIf
    Case $Box2
        If GUICtrlRead($Box1) = $GUI_CHECKED Then
            GUICtrlSetState($Box1, $GUI_UNCHECKED)
        Else
            GUICtrlSetState($Box1, $GUI_CHECKED)
        EndIf
    EndSwitch
WEnd
YOU ROCK! THANKS :)
Link to comment
Share on other sites

  • 8 months later...

why not just use Radios?

Perhaps the options are mutually exclusive, but neither is mandatory -- which is what I was looking to do.

So, in my instance, this is what the code needs to look like:

#include <GuiConstantsEx.au3>

$GUI = GUICreate("Test", 364, 600)

$Box1 = GuiCtrlCreateCheckbox("", 0, 400, 80, 20)
GuiCtrlSetState(-1, $GUI_CHECKED)

$Box2 = GUICtrlCreateCheckbox("", 0, 430, 100, 20)

GUISetState(@SW_SHOW)

While 1
    $msg = GuiGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            Exit
      Case $Box1
        If GUICtrlRead($Box2) = $GUI_CHECKED Then
            GUICtrlSetState($Box1, $GUI_CHECKED)
            GUICtrlSetState($Box2, $GUI_UNCHECKED)
        EndIf
      Case $Box2
        If GUICtrlRead($Box1) = $GUI_CHECKED Then
            GUICtrlSetState($Box2, $GUI_CHECKED)
            GUICtrlSetState($Box1, $GUI_UNCHECKED)
        EndIf
    EndSwitch
WEnd

Many thanks to Capone and rasim for getting me on the right track with this.

Edited by TheSovereign

[font="Courier New"]__________________________________________________There is always another way, usually a better one.[/font]

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...