Sign in to follow this  
Followers 0
brad25

getting check box to work with button

9 posts in this topic

hi, i need some help can someone show me how to get a checkbox to work with a button.

for instants i have 2 check boxes and a button if i check 1 box and press the button i want the scrip to messagebox checkbox1 if i check both boxes i want it to say checkbox1 checkbox2 how do i do this?

Share this post


Link to post
Share on other sites



brad25,

Here you go: :mellow:

#include <GUIConstantsEx.au3>

$hGUI = GUICreate("Test", 500, 500)

$hCheck1 = GUICtrlCreateCheckbox(" Check 1", 10, 10, 200, 20)
$hCheck2 = GUICtrlCreateCheckbox(" Check 1", 10, 50, 200, 20)
$hButton = GUICtrlCreateButton("Press!", 10, 100, 80, 30)

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hButton
            If GUICtrlRead($hCheck1) = 1 Then
                If GUICtrlRead($hCheck2) = 1 Then
                    MsgBox(0, "Checked", "Check 1 and Check 2")
                Else
                    MsgBox(0, "Checked", "Check 1")
                EndIf
            ElseIf GUICtrlRead($hCheck2) = 1 Then
                MsgBox(0, "Checked", "Check 2")
            EndIf
    EndSwitch
WEnd

As a relative beginner (nothing wrong with that - we all started there! :lol: ) reading the Help file (at least the first few sections - Using AutoIt, Tutorials and the first couple of References) will help you enormously. You might also want to look at the excellent tutorials that you will find here and here. There are even video tutorials on YouTube if you prefer watching to reading.

I know you want to start coding NOW, but a little study will save you a lot of trouble later on, believe me. :(

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

ty for the help and the advice i will use them both of tehm one other question how do i set a background to the form i have a jpeg image i want to use

Share this post


Link to post
Share on other sites

brad25,

Read about GUICtrlCreatePic in the Help file - but read it carefully! The page specifically mentions how to set a picture as background - so I do not want you complaining in a while that none of your controls work! :mellow:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

could you show me an example?

Share this post


Link to post
Share on other sites

could you show me an example?

You should try writing something and try the example in the help file that M23 directed you to. But so far you have started with only asking for someone to do things for you. It is not the best way to learn IMO. Try something, struggle with it and if you can't see how to get it to do what you want then show your code and ask for advice.


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.

Share this post


Link to post
Share on other sites

brad25,

I completely agree with martin. That is why I pointed you at the Help file.

We will be here if you have problems. :mellow:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

ok i have been going at this for hours and cant figure it out. if i check box 1 i want it to run the loop and do the

PixelGetColor but i cant get it working im guessing its because im using a if statment inside an if stament but i cant get the PixelGetColor to work without it any suggestions

#include <GUIConstantsEx.au3>

$hGUI = GUICreate("Test", 500, 500)

$hCheck1 = GUICtrlCreateCheckbox(" button1", 10, 10, 200, 20)
$hCheck2 = GUICtrlCreateCheckbox(" button2", 10, 50, 200, 20)
$hButton = GUICtrlCreateButton("Press!", 10, 100, 80, 30)

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hButton
            If GUICtrlRead($hCheck1) = 1 then
                
                
            
               

   if(0xe2900e = PixelGetColor(298, 341))  Then 
      sleep(1000)
        MouseClick("left", 539 , 411 )
         sleep(3000)
      MouseClick("left", 830 , 158 )
   EndIf
             
              
            
            
                If GUICtrlRead($hCheck2) = 1 Then
                    
            
            
    If (0xe7b486 = PixelGetColor(309, 325))  Then 
        sleep(1000)
            MouseClick("left", 555 , 409 )
             sleep(3000)
            MouseClick("left", 830 , 158 )
    EndIf   
                    
                    
                    
                Else
                  
                 EndIf
            ElseIf GUICtrlRead($hButton) = 0 Then
                MsgBox(0, "Error", "Please Check a Box")
            EndIf
    EndSwitch
WEnd

Share this post


Link to post
Share on other sites

brad25,

You have not read any of those tutorials, have you! :mellow: This is the last time I will help until you show some signs of trying to learn for yourself.

As you only want one selection each time, I have used RadioButtons in a Group so that they switch automatically:

#include <GUIConstantsEx.au3>

$hGUI = GUICreate("Test", 500, 500)

GUIStartGroup()
$hRadio1 = GUICtrlCreateRadio(" Button 1", 10, 10, 200, 20)
$hRadio2 = GUICtrlCreateRadio(" Button 2", 10, 50, 200, 20)

$hButton = GUICtrlCreateButton("Press!", 10, 100, 80, 30)

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hButton
            If GUICtrlRead($hRadio1) = 1 Then

                If PixelGetColor(298, 341) = 0xe2900e Then
                    Sleep(1000)
                    MouseClick("left", 539 , 411 )
                    sleep(3000)
                    MouseClick("left", 830 , 158 )
                EndIf

            ElseIf GUICtrlRead($hRadio2) = 1 Then

                If PixelGetColor(309, 325) = 0xe7b486 Then
                    Sleep(1000)
                    MouseClick("left", 555 , 409 )
                    Sleep(3000)
                    MouseClick("left", 830 , 158 )
                EndIf

            Else

                MsgBox(0, "Error", "Please select an option")

            EndIf
    EndSwitch
WEnd

Now go and do some studying! :(

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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