Sign in to follow this  
Followers 0
VAADAdmin

Checkbox OnEvent

9 posts in this topic

I am trying to use guictrlsetonevent on a checkbox. When I do this, the function actually fires after I uncheck the box. I want it to fire on checking. I believe I am missing something simple here and overlooking it.

#include <GUIConstants.au3>
#include <Array.au3>
#Include <GuiCombo.au3>
#Include <GuiEdit.au3>

Dim $strUserDN
Dim $Home
Dim $homeDirectory

Opt("GUIOnEventMode", 1) ; Change to OnEvent mode 

$Form1_1 = GUICreate("Tabbed Notebook Dialog", 413, 305, -884, 214)
GUISetIcon("D:05.ico")
$PageControl1 = GUICtrlCreateTab(8, 8, 396, 256)

GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents")
GUISetOnEvent($GUI_EVENT_MINIMIZE, "SpecialEvents")
GUISetOnEvent($GUI_EVENT_RESTORE, "SpecialEvents")

;TabSheet 1
$TabSheet1 = GUICtrlCreateTabItem("Copy Template")
GUICtrlSetState(-1,$GUI_SHOW)
$templateUser_combo = GUICtrlCreateCombo("", 224, 40, 161, 25)
$templateUser_lbl = GUICtrlCreateLabel("Select Template User", 104, 40, 106, 17)
$firstName_input = GUICtrlCreateInput("", 32, 96, 121, 21)
$Input2 = GUICtrlCreateInput("", 160, 96, 25, 21)
$lastName_input = GUICtrlCreateInput("", 192, 96, 185, 21)
$firstName_lbl = GUICtrlCreateLabel("First Name", 32, 80, 54, 17)
$mI_lbl = GUICtrlCreateLabel("M.I.", 160, 80, 22, 17)
$lastName_lbl = GUICtrlCreateLabel("Last Name", 192, 80, 55, 17)
$email_chkbox = GUICtrlCreateCheckbox("Create Mailbox", 32, 136, 97, 17)
$createUser_btn = GUICtrlCreateButton("Create User", 130, 225, 139, 25, 0)

GUICtrlSetOnEvent(13,"get_homeMDB")

;TabSheet 2
$TabSheet2 = GUICtrlCreateTabItem("Copy Existing User")
$firstName2_input = GUICtrlCreateInput("", 24, 112, 121, 21)
$mI2_input = GUICtrlCreateInput("", 152, 112, 33, 21)
$lastName2_input = GUICtrlCreateInput("", 192, 112, 185, 21)
$firstName2_lbl = GUICtrlCreateLabel("First Name", 24, 96, 54, 17)
$mI2_lbl = GUICtrlCreateLabel("M.I.", 152, 96, 22, 17)
$lastName2_lbl = GUICtrlCreateLabel("Last Name", 192, 96, 43, 17)
$userName2_input = GUICtrlCreateInput("", 24, 56, 89, 21)
$userName2_lbl = GUICtrlCreateLabel("User Name to Copy", 24, 40, 96, 17)
$displayName2_input = GUICtrlCreateInput("", 168, 56, 193, 21)
$userName2_btn = GUICtrlCreateButton("...", 120, 56, 27, 17, 0)
$createUser2_btn = GUICtrlCreateButton("Create User", 128, 224, 139, 25, 0)
GUICtrlSetTip(-1, "Click to Show Display Name of User")
$Checkbox1 = GUICtrlCreateCheckbox("Create Mailbox", 24, 153, 97, 17,$BS_PUSHLIKE)

$TabSheet3 = GUICtrlCreateTabItem("TabSheet3")
GUICtrlCreateTabItem("")

$Button1 = GUICtrlCreateButton("&OK", 166, 272, 75, 25, 0)
$Button2 = GUICtrlCreateButton("&Cancel", 246, 272, 75, 25, 0)
$Button3 = GUICtrlCreateButton("&Help", 328, 272, 75, 25, 0)
GUISetState(@SW_SHOW)



While 1
    Sleep(10)
WEnd

Func SpecialEvents()
    

    Select
        Case @GUI_CTRLID = $GUI_EVENT_CLOSE
           ;MsgBox(0, "Close Pressed", "ID=" & @GUI_CTRLID & " WinHandle=" & @GUI_WINHANDLE)
            Exit
            
        Case @GUI_CTRLID = $GUI_EVENT_MINIMIZE
           ;MsgBox(0, "Window Minimized", "ID=" & @GUI_CTRLID & " WinHandle=" & @GUI_WINHANDLE)
            
        Case @GUI_CTRLID = $GUI_EVENT_RESTORE
           ;MsgBox(0, "Window Restored", "ID=" & @GUI_CTRLID & " WinHandle=" & @GUI_WINHANDLE)
            
    EndSelect
    
EndFunc

    
        Func get_homeMDB()
                
                $homeMDB_combo = GUICtrlCreateCombo("", 24, 184, 361, 25)
        EndFunc

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

In the function fired, just add an 'If' statement to check if the checkbox is checked or unchecked.

Then run code accordingly.

Edited by JoshDB

Ha, I haven't been on these forums since... 2006, almost. Behold, my legacy signature:My AutoIt idol is Valuater. You know you love him, too.My Stuff: D&D AGoT Tools Suite

Share this post


Link to post
Share on other sites

Func get_homeMDB()
                if GUICtrlRead(13) = $GUI_CHECKED Then
                $homeMDB_combo = GUICtrlCreateCombo("", 24, 184, 361, 25)
                EndIf
        EndFunc

I put this in the function statement, it will now run when I check it but I have to check it twice. Check, Uncheck, Check then it will fire.

Share this post


Link to post
Share on other sites

Func get_homeMDB()
                $info = GUICtrlRead(13);read the checkbox
                if ($info = $GUI_CHECKED) Then;check if its checked
                    
                    $homeMDB_combo = GUICtrlCreateCombo("", 24, 184, 361, 25)

                EndIf
                    $homeMDB_combo = GUICtrlCreateCombo("", 24, 184, 361, 25)
                                
        EndFunc

I searched more of the forum and updated to this in my function and it does work. But it just does not look right to me. Does anyone have a better option on how to get this function to run on first checking the checkbox.

Share this post


Link to post
Share on other sites

Don't now if this was your idea?

#include <GUIConstants.au3>
#include <Array.au3>
#Include <GuiCombo.au3>
#Include <GuiEdit.au3>

Dim $strUserDN
Dim $Home
Dim $homeDirectory

Opt("GUIOnEventMode", 1) ; Change to OnEvent mode 

$Form1_1 = GUICreate("Tabbed Notebook Dialog", 413, 305, -1, -1)
GUISetIcon("D:05.ico")
$PageControl1 = GUICtrlCreateTab(8, 8, 396, 256)

GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents")
GUISetOnEvent($GUI_EVENT_MINIMIZE, "SpecialEvents")
GUISetOnEvent($GUI_EVENT_RESTORE, "SpecialEvents")

;TabSheet 1
$TabSheet1 = GUICtrlCreateTabItem("Copy Template")
GUICtrlSetState(-1,$GUI_SHOW)
$templateUser_combo = GUICtrlCreateCombo("", 224, 40, 161, 25)
$templateUser_lbl = GUICtrlCreateLabel("Select Template User", 104, 40, 106, 17)
$firstName_input = GUICtrlCreateInput("", 32, 96, 121, 21)
$Input2 = GUICtrlCreateInput("", 160, 96, 25, 21)
$lastName_input = GUICtrlCreateInput("", 192, 96, 185, 21)
$firstName_lbl = GUICtrlCreateLabel("First Name", 32, 80, 54, 17)
$mI_lbl = GUICtrlCreateLabel("M.I.", 160, 80, 22, 17)
$lastName_lbl = GUICtrlCreateLabel("Last Name", 192, 80, 55, 17)
$email_chkbox = GUICtrlCreateCheckbox("Create Mailbox", 32, 136, 97, 17)
$createUser_btn = GUICtrlCreateButton("Create User", 130, 225, 139, 25, 0)
$homeMDB_combo = GUICtrlCreateCombo("", 24, 184, 361, 25)
GUICtrlSetState(-1,$GUI_HIDE)

;TabSheet 2
$TabSheet2 = GUICtrlCreateTabItem("Copy Existing User")
$firstName2_input = GUICtrlCreateInput("", 24, 112, 121, 21)
$mI2_input = GUICtrlCreateInput("", 152, 112, 33, 21)
$lastName2_input = GUICtrlCreateInput("", 192, 112, 185, 21)
$firstName2_lbl = GUICtrlCreateLabel("First Name", 24, 96, 54, 17)
$mI2_lbl = GUICtrlCreateLabel("M.I.", 152, 96, 22, 17)
$lastName2_lbl = GUICtrlCreateLabel("Last Name", 192, 96, 43, 17)
$userName2_input = GUICtrlCreateInput("", 24, 56, 89, 21)
$userName2_lbl = GUICtrlCreateLabel("User Name to Copy", 24, 40, 96, 17)
$displayName2_input = GUICtrlCreateInput("", 168, 56, 193, 21)
$userName2_btn = GUICtrlCreateButton("...", 120, 56, 27, 17, 0)
$createUser2_btn = GUICtrlCreateButton("Create User", 128, 224, 139, 25, 0)
GUICtrlSetTip(-1, "Click to Show Display Name of User")
$Checkbox1 = GUICtrlCreateCheckbox("Create Mailbox", 24, 153, 97, 17,$BS_PUSHLIKE)

$TabSheet3 = GUICtrlCreateTabItem("TabSheet3")
GUICtrlCreateTabItem("")

$Button1 = GUICtrlCreateButton("&OK", 166, 272, 75, 25, 0)
$Button2 = GUICtrlCreateButton("&Cancel", 246, 272, 75, 25, 0)
$Button3 = GUICtrlCreateButton("&Help", 328, 272, 75, 25, 0)
GUISetState(@SW_SHOW)



While 1
    if GUICtrlRead($email_chkbox) = $GUI_CHECKED Then 
        GUICtrlSetState($homeMDB_combo,$GUI_SHOW)
    ElseIf GUICtrlRead($email_chkbox) = $GUI_UNCHECKED Then
        GUICtrlSetState($homeMDB_combo,$GUI_HIDE)
    EndIf
    Sleep(100)
WEnd

Func SpecialEvents()
    Select
        Case @GUI_CTRLID = $GUI_EVENT_CLOSE
           ;MsgBox(0, "Close Pressed", "ID=" & @GUI_CTRLID & " WinHandle=" & @GUI_WINHANDLE)
            Exit
        Case @GUI_CTRLID = $GUI_EVENT_MINIMIZE
           ;MsgBox(0, "Window Minimized", "ID=" & @GUI_CTRLID & " WinHandle=" & @GUI_WINHANDLE)
        Case @GUI_CTRLID = $GUI_EVENT_RESTORE
           ;MsgBox(0, "Window Restored", "ID=" & @GUI_CTRLID & " WinHandle=" & @GUI_WINHANDLE)
    EndSelect
EndFunc

Neo


[center][font="Arial"]--- The Neo and Only --- [/font][font="Arial"]--Projects---[/font]Image to Text converterText to ASCII converter[/center]

Share this post


Link to post
Share on other sites

This is a code from the programm "Windows XP Install-Suite"

CODE

$tab_programs_settings = GUICtrlCreateCheckbox("Individuelle Einstellungen festlegen", 220, 200, 200)

GUICtrlSetOnEvent(-1, "_show_settingsgroup")

Func _show_settingsgroup()

If GUICtrlRead($tab_programs_settings) = $GUI_CHECKED Then

; Group

GUICtrlSetState($tab_programs_settings_group, $GUI_ENABLE)

; Setup-Parameter

GUICtrlSetState($tab_programs_parameter_label, $GUI_ENABLE)

GUICtrlSetState($tab_programs_parameter_input, $GUI_ENABLE)

; Serial-Eingabe

GUICtrlSetState($tab_programs_serial_label, $GUI_ENABLE)

GUICtrlSetState($tab_programs_serial_input, $GUI_ENABLE)

; Programme-Ordner

GUICtrlSetState($tab_programs_path_label, $GUI_ENABLE)

GUICtrlSetState($tab_programs_path_label, $GUI_ENABLE)

; Desktop

GUICtrlSetState($tab_programs_desktop_label, $GUI_ENABLE)

Else

; Group

GUICtrlSetState($tab_programs_settings_group, $GUI_DISABLE)

; Setup-Parameter

GUICtrlSetState($tab_programs_parameter_label, $GUI_DISABLE)

GUICtrlSetState($tab_programs_parameter_input, $GUI_DISABLE)

; Serial-Eingabe

GUICtrlSetState($tab_programs_serial_label, $GUI_DISABLE)

GUICtrlSetState($tab_programs_serial_input, $GUI_DISABLE)

; Programme-Ordner

GUICtrlSetState($tab_programs_path_label, $GUI_DISABLE)

GUICtrlSetState($tab_programs_path_input, $GUI_DISABLE)

; Desktop

GUICtrlSetState($tab_programs_desktop_label, $GUI_DISABLE)

EndIf

EndFunc ;==>_show_settingsgroup

Share this post


Link to post
Share on other sites

Thanks for the help eveyone. Neofox, that is what I was looking for, I have it working well in my program now.

Share this post


Link to post
Share on other sites

@VAADAdmin: My Script is better, because when you are clicking on the checkbox, then run the function "_show_settingsgroup". And this function is examine is the Checkbox CHECKED or UNCHECKED

Share this post


Link to post
Share on other sites

Thanks, I will take a look at both more in depth and see the difference.

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