Sign in to follow this  
Followers 0
lemony

is there a way to disable/enable all controls within a group in one shot?

6 posts in this topic

#1 ·  Posted (edited)

Hey guys,

So lets say I have a group with a couple of controls (some checkboxes, textboxes and things like that.)

If I want to disable all these controls I have to do a GUICtrlSetState on each one of them until I disable them all. And then to enable them I have to do it all over again on each one of them.

I want to clean up some of my code. Is there a way to just disable/enable all the controls within a group in one shot?

I tried to apply a GUICtrlSetState to the actual groupbox, but it doesn't do anything.

All I'm looking for is a simple way of doing this that I may have overlooked.

If it can only be done with heavy coding or some kind of custom function then it is not good for me as it will just add more code when I am trying to clean it up :)

Thanks :)

Edited by lemony

Share this post


Link to post
Share on other sites

Use Arrays to create the controls then you can loop through them with for/next and use GUICtrlSetState() in the middle of the loop

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Oh very cool! I would have never thought of that :)

Thanks Valuater :)

Edited by lemony

Share this post


Link to post
Share on other sites

lemony

Example:

#include <GuiConstantsEx.au3>

$hGUI = GUICreate("Test GUI", 300, 200)

$DummyStart = GUICtrlCreateDummy()

GUICtrlCreateInput("", 50, 50, 200, 20)

GUICtrlCreateCheckbox("CheckBox", 50, 100, 65, 20)

GUICtrlCreateButton("Button", 150, 100, 75, 23)

$DummyEnd = GUICtrlCreateDummy()

$DisButton = GUICtrlCreateButton("Disable", 10, 160, 75, 23)

GUISetState()

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $DisButton
            If GUICtrlRead($DisButton) = "Disable" Then
                GUICtrlSetData($DisButton, "Enable")
                _Disable($GUI_DISABLE)
            Else
                GUICtrlSetData($DisButton, "Disable")
                _Disable($GUI_ENABLE)
            EndIf
    EndSwitch
WEnd

Func _Disable($sState)
    For $i = $DummyStart To $DummyEnd
        GUICtrlSetState($i, $sState)
    Next
EndFunc
:)

Share this post


Link to post
Share on other sites

WOW that's an excellent code rasim, thanks!

I never knew about GUICtrlCreateDummy or what it was meant for. But this is a nice way to use that!

It works exactly for what I need :)

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