FlatMetcher Posted July 1, 2023 Share Posted July 1, 2023 Hi there, I've a GUI I want to update on the fly to include some extra fields when certain radio values are selected. See the screenshot: When I select "Yes" for any of the radios, I want to have an inputbox type control appear (or become active) alongside the yes radio for the end user to fill in. Can post code if neccesary - I guess it requires "gui on event mode" to poll for changes to the state of the radios..... Link to comment Share on other sites More sharing options...
Solution Andreik Posted July 1, 2023 Solution Share Posted July 1, 2023 (edited) $hMain = GUICreate('Example', 400, 300) $cGroup1 = GUICtrlCreateGroup('Do you wish ... ?', 10, 10, 380, 100) $cNoGroup1 = GUICtrlCreateRadio('No', 30, 40, 50, 20) $cYesGroup1 = GUICtrlCreateRadio('Yes', 30, 70, 50, 20) $cInputGroup1 = GUICtrlCreateInput('', 80, 70, 200, 20) GUICtrlCreateGroup('', -99, -99, 1, 1) $cGroup2 = GUICtrlCreateGroup('Do you wish ... ?', 10, 120, 380, 100) $cNoGroup2 = GUICtrlCreateRadio('No', 30, 150, 50, 20) $cYesGroup2 = GUICtrlCreateRadio('Yes', 30, 180, 50, 20) $cInputGroup2 = GUICtrlCreateInput('', 80, 180, 200, 20) GUICtrlCreateGroup('', -99, -99, 1, 1) $cGoButton = GUICtrlCreateButton('Go', 50, 240, 100, 30) $cExitButton = GUICtrlCreateButton('Exit', 250, 240, 100, 30) GUICtrlSetState($cInputGroup1, 128) ; GUI_DISABLE GUICtrlSetState($cInputGroup2, 128) ; GUI_DISABLE GUISetState(@SW_SHOW) While True Switch GUIGetMsg() Case $cNoGroup1 GUICtrlSetState($cInputGroup1, 128) ; GUI_DISABLE Case $cYesGroup1 GUICtrlSetState($cInputGroup1, 64) ; GUI_ENABLE Case $cNoGroup2 GUICtrlSetState($cInputGroup2, 128) ; GUI_DISABLE Case $cYesGroup2 GUICtrlSetState($cInputGroup2, 64) ; GUI_ENABLE Case $cGoButton ConsoleWrite('Group #1 selection: ' & (GUICtrlRead($cNoGroup1) = 1 ? 'No' : 'Yes (' & GUICtrlRead($cInputGroup1) & ')') & @CRLF) ConsoleWrite('Group #2 selection: ' & (GUICtrlRead($cNoGroup2) = 1 ? 'No' : 'Yes (' & GUICtrlRead($cInputGroup2) & ')') & @CRLF) Case $cExitButton, -3 ; GUI_EVENT_CLOSE Exit EndSwitch WEnd Or the input can be completely hidden, not just disabled. $hMain = GUICreate('Example', 400, 300) $cGroup1 = GUICtrlCreateGroup('Do you wish ... ?', 10, 10, 380, 100) $cNoGroup1 = GUICtrlCreateRadio('No', 30, 40, 50, 20) $cYesGroup1 = GUICtrlCreateRadio('Yes', 30, 70, 50, 20) $cInputGroup1 = GUICtrlCreateInput('', 80, 70, 200, 20) GUICtrlCreateGroup('', -99, -99, 1, 1) $cGroup2 = GUICtrlCreateGroup('Do you wish ... ?', 10, 120, 380, 100) $cNoGroup2 = GUICtrlCreateRadio('No', 30, 150, 50, 20) $cYesGroup2 = GUICtrlCreateRadio('Yes', 30, 180, 50, 20) $cInputGroup2 = GUICtrlCreateInput('', 80, 180, 200, 20) GUICtrlCreateGroup('', -99, -99, 1, 1) $cGoButton = GUICtrlCreateButton('Go', 50, 240, 100, 30) $cExitButton = GUICtrlCreateButton('Exit', 250, 240, 100, 30) GUICtrlSetState($cInputGroup1, 32) ; GUI_HIDE GUICtrlSetState($cInputGroup2, 32) ; GUI_HIDE GUISetState(@SW_SHOW) While True Switch GUIGetMsg() Case $cNoGroup1 GUICtrlSetState($cInputGroup1, 32) ; GUI_HIDE Case $cYesGroup1 GUICtrlSetState($cInputGroup1, 16) ; GUI_SHOW Case $cNoGroup2 GUICtrlSetState($cInputGroup2, 32) ; GUI_HIDE Case $cYesGroup2 GUICtrlSetState($cInputGroup2, 16) ; GUI_SHOW Case $cGoButton ConsoleWrite('Group #1 selection: ' & (GUICtrlRead($cNoGroup1) = 1 ? 'No' : 'Yes (' & GUICtrlRead($cInputGroup1) & ')') & @CRLF) ConsoleWrite('Group #2 selection: ' & (GUICtrlRead($cNoGroup2) = 1 ? 'No' : 'Yes (' & GUICtrlRead($cInputGroup2) & ')') & @CRLF) Case $cExitButton, -3 ; GUI_EVENT_CLOSE Exit EndSwitch WEnd Or if you have to create a bunch of these groups you might consider to create them dynamically: expandcollapse popupGlobal $hMain, $aUIGroups[6], $aUIYesRadio[6], $aUINoRadio[6], $aUIInput[6] Global $nMsg, $YesSelected, $NoSelected $hMain = GUICreate('Example', 400, 780) For $Index = 0 To UBound($aUIGroups) - 1 $aUIGroups[$Index] = GUICtrlCreateGroup('Do you wish ... ?', 10, $Index * 120 + 10, 380, 100) $aUINoRadio[$Index] = GUICtrlCreateRadio('No', 30, $Index * 120 + 40, 50, 20) $aUIYesRadio[$Index] = GUICtrlCreateRadio('Yes', 30, $Index * 120 + 70, 50, 20) $aUIInput[$Index] = GUICtrlCreateInput('', 80, $Index * 120 + 70, 200, 20) GUICtrlCreateGroup('', -99, -99, 1, 1) GUICtrlSetState($aUIInput[$Index], 32) ; GUI_HIDE Next $cGoButton = GUICtrlCreateButton('Go', 50, 730, 100, 30) $cExitButton = GUICtrlCreateButton('Exit', 250, 730, 100, 30) GUISetState(@SW_SHOW) While True $nMsg = GUIGetMsg() $YesSelected = InArray($aUIYesRadio, $nMsg) If $YesSelected Then GUICtrlSetState($YesSelected + 1, 16) ; GUI_SHOW $NoSelected = InArray($aUINoRadio, $nMsg) If $NoSelected Then GUICtrlSetState($NoSelected + 2, 32) ; GUI_HIDE Switch $nMsg Case $cGoButton For $Index = 0 To UBound($aUIGroups) - 1 ConsoleWrite('Group #' & $Index + 1 & ' selection: ' & (GUICtrlRead($aUINoRadio[$Index]) = 1 ? 'No' : 'Yes (' & GUICtrlRead($aUIInput[$Index]) & ')') & @CRLF) Next Case $cExitButton, -3 ; GUI_EVENT_CLOSE Exit EndSwitch WEnd Func InArray($aArray, $nValue) For $Index = 0 To UBound($aArray) - 1 If $aArray[$Index] = $nValue Then Return $aArray[$Index] Next Return 0 EndFunc Edited July 1, 2023 by Andreik When the words fail... music speaks. Link to comment Share on other sites More sharing options...
FlatMetcher Posted July 2, 2023 Author Share Posted July 2, 2023 Wow - that's awesome @Andreik Thanks soooo much for the speedy reply Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now