Sign in to follow this  
Followers 0
SwissWrist

Using GUICtrlSetOnEvent to enable & disable radio buttons & clear the state of radio buttons

4 posts in this topic

#1 ·  Posted (edited)

Hello,  I'm very very new to autoit and have been doing my best to learn.  I'm wondering if anyone could help me.

I have a little GUI where i'm trying to enable and disable radio buttons in certain scenarios.

$radio_1 is selected by default so I would like $radio_4 and $radio_5 to be disabled when the dialog is first run. 

If $radio_2 or $radio_3 are selected I would like $radio_4 and $radio_5 to be enabled.

If $radio_4 or $radio_5 are selected while enalbed and the user selects $radio_1 I would like the selection of $radio_4 or $radio_5 to clear and become disabled.

Thanks.

#include <GUIConstantsEx.au3>
#include <GuiButton.au3>
#include <Test.au3>


$GUI = GUICreate("Enterprise Auto Install", 300, 300)

GUIStartGroup()
$radio_1 = GUICtrlCreateRadio("Client", 20, 30, 400, 20)
$radio_2 = GUICtrlCreateRadio("Client/Server", 20, 50, 400, 20)
$radio_3 = GUICtrlCreateRadio("Application Server", 20, 70, 400, 20)
GUIStartGroup()
GUIStartGroup()
$radio_4 = GUICtrlCreateRadio("SQL Authentication", 20, 130, 400, 20)
$radio_5 = GUICtrlCreateRadio("Windows Authentication", 20, 150, 400, 20)
GUIStartGroup()
$radio_6 = GUICtrlCreateRadio("Yes", 20, 210, 400, 20)
$radio_7 = GUICtrlCreateRadio("No", 20, 230, 400, 20)
GUIStartGroup()

$group_1 = GUICtrlCreateGroup("Install Type?", 10, 10, 180, 90)
$group_2 = GUICtrlCreateGroup("Authentication", 10, 110, 180, 70)
$group_3 = GUICtrlCreateGroup("Run Dev Build?", 10, 190, 180, 70)



if @OSArch = "X64" Then
    $slq8 = RegRead ("HKEY_LOCAL_MACHINE64\SOFTWARE\Microsoft\Microsoft SQL Server\SQLNCLI10\CurrentVersion\","Version")
    $sql12 = RegRead("HKEY_LOCAL_MACHINE64\SOFTWARE\Microsoft\Microsoft SQL Server\SQLNCLI11\CurrentVersion\", "Version")
Else
    $slq8 = RegRead ("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\SQLNCLI10\CurrentVersion\","Version")
    $sql12 = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\SQLNCLI11\CurrentVersion\", "Version")
EndIf


If $slq8 = "" and $sql12 = "" Then
    For $I = $radio_4 To $radio_5
    GUICtrlSetState($I, $GUI_DISABLE) ; $GUI_DISABLE is needed to disable the control
    Next
EndIf




GUICtrlSetState($radio_1, $GUI_CHECKED)
GUICtrlSetState($radio_7, $GUI_CHECKED)



GUISetState()

While 1
    $ans = GUICtrlRead ($radio_1)
if $ans = 1 Then
    GUICtrlSetOnEvent (3, disable())

Else
    GUICtrlSetOnEvent (3, enable())
EndIf
WEnd




While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE, $idClose
            Exit
    EndSwitch
WEnd
#include <GUIConstantsEx.au3>
#include <GuiButton.au3>



Func disable()
    For $F = 6 To 7
    GUICtrlSetState($F, $GUI_DISABLE)
    Next
EndFunc

Func enable()
    For $F = 6 To 7
    GUICtrlSetState($F, $GUI_ENABLE)
    Next
EndFunc

 
Edited by SwissWrist

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Welcome to the AutoIt forum SwissWrist! :D

First off, having two different loops to catch events in a GUI is mute as you'll never be able to catch events on the radio if your in the GUI loop and vise versa.

Secondly, when the radio buttons are clicked, they will give off the same event as any other event on a GUI. Here is your loop put together (and I checked the first radio and disabled 4 and 5 to show you). ;)

GUICtrlSetState($radio_1, $GUI_CHECKED)

GUICtrlSetState($radio_4, $GUI_DISABLE)
GUICtrlSetState($radio_5, $GUI_DISABLE)

Local $msg

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE, $idClose
            Exit
        Case $radio_1
            GUICtrlSetState($radio_4, $GUI_DISABLE)
            GUICtrlSetState($radio_5, $GUI_DISABLE)
        Case $radio_2
            GUICtrlSetState($radio_4, $GUI_ENABLE)
            GUICtrlSetState($radio_5, $GUI_ENABLE)
        Case $radio_3
            GUICtrlSetState($radio_4, $GUI_ENABLE)
            GUICtrlSetState($radio_5, $GUI_ENABLE)
    EndSwitch
WEnd
Edited by MikahS

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Share this post


Link to post
Share on other sites

 

Welcome to the AutoIt forum SwissWrist! :D

First off, having two different loops to catch events in a GUI is mute as you'll never be able to catch events on the radio if your in the GUI loop and vise versa.

Secondly, when the radio buttons are clicked, they will give off the same event as any other event on a GUI. Here is your loop put together (and I checked the first radio and disabled 4 and 5 to show you). ;)

GUICtrlSetState($radio_1, $GUI_CHECKED)

GUICtrlSetState($radio_4, $GUI_DISABLE)
GUICtrlSetState($radio_5, $GUI_DISABLE)

Local $msg

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE, $idClose
            Exit
        Case $radio_1
            GUICtrlSetState($radio_4, $GUI_DISABLE)
            GUICtrlSetState($radio_5, $GUI_DISABLE)
        Case $radio_2
            GUICtrlSetState($radio_4, $GUI_ENABLE)
            GUICtrlSetState($radio_5, $GUI_ENABLE)
        Case $radio_3
            GUICtrlSetState($radio_4, $GUI_ENABLE)
            GUICtrlSetState($radio_5, $GUI_ENABLE)
    EndSwitch
WEnd

 

Greatly appreciated!

Thank you, MikahS!

Share this post


Link to post
Share on other sites

My pleasure. ;)


Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

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