Jump to content

Disable control if radio button is checked


Recommended Posts

I have the following code which works but the box keeps flickering and the input boxes seem to be ungreyed some times.

#include <GuiConstants.au3>
GUICreate("Radio buttons - Select details", 469, 250, (@DesktopWidth - 469) / 2, (@DesktopHeight - 250) / 2, $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS)
; GROUP WITH RADIO BUTTONS
GUICtrlCreateGroup("Number of versions to test", 10, 10, 180, 40)
$radio1 = GUICtrlCreateRadio("One", 20, 25, 50)
GUICtrlSetState(-1, $GUI_CHECKED)
$radio2 = GUICtrlCreateRadio("Two", 70, 25, 50)
$radio3 = GUICtrlCreateRadio("Three", 120, 25, 50)
GUICtrlCreateGroup("", -99, -99, 1, 1) ;close group
;Now draw all of the path input controls
GUICtrlCreateLabel("Path 1", 10, 70, 150, 20)
GUICtrlCreateLabel("Path 2", 10, 100, 150, 20)
GUICtrlCreateLabel("Path 3", 10, 130, 150, 20)
GUICtrlCreateInput("c:\", 180, 70, 280, 20)
GUICtrlCreateInput("c:\", 180, 100, 280, 20)
GUICtrlCreateInput("c:\", 180, 130, 280, 20)
;Logic to work out State of paths boxes according to checkbox state
GUISetState()
While 1
   $msg = GUIGetMsg()
   Select
      Case $msg = $GUI_EVENT_CLOSE
         ExitLoop
         Case   GUICtrlRead ($radio1) = $GUI_CHECKED
         GUICtrlCreateInput("c:\", 180, 100, 280, 20)
         GUICtrlSetState(-1, $GUI_DISABLE)
         GUICtrlCreateInput("c:\", 180, 130, 280, 20)
         GUICtrlSetState(-1, $GUI_DISABLE)
      Case GUICtrlRead($radio2) = $GUI_CHECKED
         GUICtrlCreateInput("c:\", 180, 100, 280, 20)
         GUICtrlCreateInput("c:\", 180, 130, 280, 20)
         GUICtrlSetState(-1, $GUI_DISABLE)
      Case GUICtrlRead($radio3) = $GUI_CHECKED
         GUICtrlCreateInput("c:\", 180, 70, 280, 20)
         GUICtrlCreateInput("c:\", 180, 100, 280, 20)
         GUICtrlCreateInput("c:\", 180, 130, 280, 20)
      Case Else
        ;;;
   EndSelect
WEnd
Exit

What I want to do is disable the input boxes that are not needed. So if the radio button is on one then the second and third path boxes are not relevant and so should be disabled.

Second point how would I then pass the path from the input box to a variable I can use later in the script?

Link to comment
Share on other sites

Something like this?

#include <GuiConstants.au3>
GUICreate("Radio buttons - Select details", 469, 250, (@DesktopWidth - 469) / 2, (@DesktopHeight - 250) / 2, $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS)
; GROUP WITH RADIO BUTTONS
GUICtrlCreateGroup("Number of versions to test", 10, 10, 180, 40)
$radio1 = GUICtrlCreateRadio("One", 20, 25, 50)
GUICtrlSetState(-1, $GUI_CHECKED)
$radio2 = GUICtrlCreateRadio("Two", 70, 25, 50)
$radio3 = GUICtrlCreateRadio("Three", 120, 25, 50)
GUICtrlCreateGroup("", -99, -99, 1, 1);close group
;Now draw all of the path input controls
GUICtrlCreateLabel("Path 1", 10, 70, 150, 20)
GUICtrlCreateLabel("Path 2", 10, 100, 150, 20)
GUICtrlCreateLabel("Path 3", 10, 130, 150, 20)
$Input1 = GUICtrlCreateInput("c:\", 180, 70, 280, 20)
$Input2 = GUICtrlCreateInput("c:\", 180, 100, 280, 20)
$Input3 = GUICtrlCreateInput("c:\", 180, 130, 280, 20)
;Logic to work out State of paths boxes according to checkbox state
GUICtrlSetstate($Input2,$GUI_DISABLE)
        GUICtrlSetstate($Input3,$GUI_DISABLE)
GUISetState()
While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then Exit
 
    If $msg = $Radio1 AND GUICTRLRead($Radio1) = $GUI_CHECKED Then 
        GUICtrlSetstate($Input1,$GUI_ENABLE)
        GUICtrlSetstate($Input2,$GUI_DISABLE)
        GUICtrlSetstate($Input3,$GUI_DISABLE)
    EndIf
    If $msg = $Radio2 AND GUICTRLRead($Radio2) = $GUI_CHECKED Then 
        GUICtrlSetstate($Input1,$GUI_ENABLE)
        GUICtrlSetstate($Input2,$GUI_ENABLE)
        GUICtrlSetstate($Input3,$GUI_DISABLE)
    EndIf
    If $msg = $Radio3 AND GUICTRLRead($Radio3) = $GUI_CHECKED Then 
        GUICtrlSetstate($Input1,$GUI_ENABLE)
        GUICtrlSetstate($Input2,$GUI_ENABLE)
        GUICtrlSetstate($Input3,$GUI_ENABLE)
    EndIf
WEnd
Exit

EDIT: Your input boxes were flickering bacause the (radio is checked) is true every time it passes the while.. so it would create a new input every time! This way you only set the state of is, if the radio is pressed AND it is checked..

Edited by Wb-FreeKill
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...