Jump to content

Check if a checkbox is checked


BALA
 Share

Recommended Posts

#include <GUIConstants.au3>

GUICreate("My GUI Checkbox")  ; will create a dialog box that when displayed is centered

$checkCN = GUICtrlCreateCheckbox ("CHECKBOX 1", 10, 10, 120, 20)

GUISetState ()       ; will display an  dialog box with 1 checkbox

; Run the GUI until the dialog is closed
While 1
    $msg = GUIGetMsg()
    
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
Wend

How would i be able to "check" if this checkbox is checked, and cause a dialog box to open when it it checked.

[font="Comic Sans MS"]BA-LA[/font]http://ba-la.110mb.comJoin my community, CLICK HEREAlternative links to my site:http://www.ba-la.tkhttp://www.ba-la.co.nrContact me if you would like to help with some of my projects: joeythepirate@gmail.com
Link to comment
Share on other sites

Read the Help File

;-------------------------------------------------------------------------------------
; Example - Press the button to see the value of the radio boxes
; The script also detects state changes (closed/minimized/timeouts, etc).

#include <GUIConstants.au3>

Opt("GUICoordMode", 1)
GUICreate("Radio Box Demo", 400,280)

; Create the controls
$button_1 = GUICtrlCreateButton ("B&utton 1", 30, 20, 120, 40)
$group_1 = GUICtrlCreateGroup ("Group 1", 30, 90, 165, 160)
GUIStartGroup()
$radio_1 = GUICtrlCreateRadio ("Radio &0", 50, 120, 70, 20)
$radio_2 = GUICtrlCreateRadio ("Radio &1", 50, 150, 60, 20)
$radio_3 = GUICtrlCreateRadio ("Radio &2", 50, 180, 60, 20)

; Init our vars that we will use to keep track of GUI events
$radioval1 = 0    ; We will assume 0 = first radio button selected, 2 = last button
$radioval2 = 2

; Show the GUI
GUISetState ()

; In this message loop we use variables to keep track of changes to the radios, another
; way would be to use GUICtrlRead() at the end to read in the state of each control
While 1
   $msg = GUIGetMsg()
   Select
       Case $msg = $GUI_EVENT_CLOSE
         MsgBox(0, "", "Dialog was closed") 
         Exit
      Case $msg = $GUI_EVENT_MINIMIZE
         MsgBox(0,"", "Dialog minimized",2)
      Case $msg = $GUI_EVENT_MAXIMIZE
         MsgBox(0,"", "Dialog restored",2)
   
      Case $msg = $button_1
         MsgBox(0, "Default button clicked", "Radio " & $radioval1 )
         
      Case $msg >= $radio_1 AND $msg <= $radio_3
         $radioval1 = $msg - $radio_1

   EndSelect
WEnd

Just use a checkbox.

Link to comment
Share on other sites

So I'm replacing the radio with a checkbox?

The problem is that I don't know which Event ID to use.

$GUI_CHECKED?

If GUICtrlRead($checkCN) = $GUI_CHECKED Then
Edited by BALA
[font="Comic Sans MS"]BA-LA[/font]http://ba-la.110mb.comJoin my community, CLICK HEREAlternative links to my site:http://www.ba-la.tkhttp://www.ba-la.co.nrContact me if you would like to help with some of my projects: joeythepirate@gmail.com
Link to comment
Share on other sites

Yes. Try that.

The help file doesn't directly show you how to get the state of a checkbox.

Here is a simple example

#include <GUIConstants.au3>

GUICreate("My GUI Checkbox")  ; will create a dialog box that when displayed is centered

$checkCN = GUICtrlCreateCheckbox ("CHECKBOX 1", 10, 10, 120, 20)

GUISetState ()       ; will display an  dialog box with 1 checkbox

; Run the GUI until the dialog is closed
While 1
    $msg = GUIGetMsg()
   
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
    
    If $msg = $checkCN Then
        $cstate = Bitand(GUICtrlRead($checkCN),$GUI_CHECKED)
        if $cstate = $GUI_CHECKED then MsgBox(0,'','$check is checked')
    EndIf
        
Wend
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

  • 3 months later...

Use this:

#include <GUIConstants.au3>

$blah = GUICtrlRead($yourcheckbox)
If $blah = $GUI_CHECKED Then
   ;do stuff
ElseIf $blah = $GUI_UNCHECKED Then
   ;do other stuff
EndIf
Edited by sandman

[center]"Yes, [our app] runs on Windows as well as Linux, but if you had a Picasso painting, would you put it in the bathroom?" -BitchX.com (IRC client)"I would change the world, but they won't give me the source code." -Unknownsite . blog . portfolio . claimidcode.is.poetry();[/center]

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