Jump to content

Group/Radio button question


Jewtus
 Share

Go to solution Solved by JLogan3o13,

Recommended Posts

I have a group

$ModeGroup = GUICtrlCreateGroup("Mode", 280, 8, 97, 65)
 
and there are two radio buttons in it
$Radio = GUICtrlCreateRadio("1", 288, 24, 81, 17)
$Radio2 = GUICtrlCreateRadio("2", 288, 44, 81, 17)

 

and I'm trying to make a case statement that when one of the radio buttons is selected, different parts of the GUI show or hide. This is what I tried, but its not working:

 
Case $ModeGroup
  If GUICtrlRead($Radio) = 1 Then
     GUICtrlSetState($DODLabel,$GUI_SHOW)
     GUICtrlSetState($DODInput,$GUI_SHOW)
  Else
     GUICtrlSetState($DODLabel,$GUI_HIDE)
     GUICtrlSetState($DODInput,$GUI_HIDE)
  EndIf

What am I doing wrong? 

Link to comment
Share on other sites

  • Moderators

How are you controlling the change, through a button or immediately when you click on the radio button (full, runnable code would be awesome if you want assistance)? This works for me:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

GUICreate("Test", 500, 500)

$ModeGroup = GUICtrlCreateGroup("Mode", 280, 8, 97, 65)

$Radio = GUICtrlCreateRadio("1", 288, 24, 81, 17)
$Radio2 = GUICtrlCreateRadio("2", 288, 44, 81, 17)

$lbl = GUICtrlCreateLabel("Test", 100, 400, 100, 20)

$btn = GUICtrlCreateButton("Go", 10, 400, 60, 40)

GUISetState(@SW_SHOW)

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $btn
                GUICtrlSetState($lbl, (GUICtrlRead($Radio) = 1) ? $GUI_SHOW : $GUI_HIDE)
        EndSwitch
    WEnd

GUIDelete()

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Its a pretty long script (this is part of the main GUI and there are about 5 guis in the script)

I am trying to get the function to activate on click and not on a button click. I was hoping that setting the case to the group control would make it so when the group control was clicked, it would activate the case statement and then read the radio buttons.

The example you posted is very similar to the parts of the script that I'm using. I am using a label and an input rather than just a label.

 

Also, a question about what you posted... This line

GUICtrlSetState($lbl, (GUICtrlRead($Radio) = 1) ? $GUI_SHOW : $GUI_HIDE)

Does that look at a control and toggle based on the control? I understand that you are setting the label state and reading the radio control, but I don't understand the syntax for the 

? $GUI_SHOW : $GUI_HIDE
Edited by Jewtus
Link to comment
Share on other sites

  • Moderators

I get that your script is long, but adding the parts relevant to your question helps us help you. For example, are you using a switch like I am and GUIGetMsg, or are you using GUISetOnEvent?

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Sure thing, Here is the GUI part that I generate with KODA:

$Main = GUICreate("Parameter Entry", 385, 135, 192, 114)
$File = GUICtrlCreateMenu("&File")
$ProcessFile = GUICtrlCreateMenuItem("Process by File"&@TAB&"Ctrl+F", $File)
$SearchTypeLabel = GUICtrlCreateLabel("Search Type:", 4, 12, 85, 20)
GUICtrlSetFont(-1, 11, 400, 0, "MS Sans Serif")
$SearchTypeCombo = GUICtrlCreateCombo("", 93, 10, 153, 25)
GUICtrlSetData(-1, "Person Name|ID search")
$ParameterLabel = GUICtrlCreateLabel("Parameter:", 4, 41, 85, 20)
GUICtrlSetFont(-1, 11, 400, 0, "MS Sans Serif")
$ParameterInput = GUICtrlCreateInput("", 93, 39, 153, 21)

$ModeGroup = GUICtrlCreateGroup("Mode", 280, 8, 97, 65)
GUIStartGroup()
$Radio = GUICtrlCreateRadio("1", 288, 24, 81, 17)
GUICtrlSetState(-1,$GUI_CHECKED)
$Radio2 = GUICtrlCreateRadio("2", 288, 44, 81, 17)

$DODLabel = GUICtrlCreateLabel("Date", 10, 70, 85, 20)
GUICtrlSetFont(-1, 11, 400, 0, "MS Sans Serif")
$DODInput = GUICtrlCreateDate("", 123, 68, 123, 21,(0x00))
$Button1 = GUICtrlCreateButton("Submit", 296, 77, 75, 25)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
$cEnterDummy = GUICtrlCreateDummy()
$cFileDummy = GUICtrlCreateDummy()
Local $aAccelKeys[2][2] = [["{ENTER}", $cEnterDummy],["^f", $cFileDummy]]
GUISetAccelerators($aAccelKeys)
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE

EndSwitch
WEnd
Edited by Jewtus
Link to comment
Share on other sites

  • Moderators
  • Solution

What about something like this?

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Opt("GUIOnEventMode", 1)

$Main = GUICreate("Parameter Entry", 385, 135, 192, 114)
$File = GUICtrlCreateMenu("&File")
$ProcessFile = GUICtrlCreateMenuItem("Process by File"&@TAB&"Ctrl+F", $File)
$SearchTypeLabel = GUICtrlCreateLabel("Search Type:", 4, 12, 85, 20)
GUICtrlSetFont(-1, 11, 400, 0, "MS Sans Serif")
$SearchTypeCombo = GUICtrlCreateCombo("", 93, 10, 153, 25)
GUICtrlSetData(-1, "Person Name|ID search")
$ParameterLabel = GUICtrlCreateLabel("Parameter:", 4, 41, 85, 20)
GUICtrlSetFont(-1, 11, 400, 0, "MS Sans Serif")
$ParameterInput = GUICtrlCreateInput("", 93, 39, 153, 21)

$ModeGroup = GUICtrlCreateGroup("Mode", 280, 8, 97, 65)
GUIStartGroup()
$Radio = GUICtrlCreateRadio("1", 288, 24, 81, 17)
    GUICtrlSetOnEvent(-1, "setState")

$Radio2 = GUICtrlCreateRadio("2", 288, 44, 81, 17)
    GUICtrlSetOnEvent(-1, "setState")

$DODLabel = GUICtrlCreateLabel("Date", 10, 70, 85, 20)
GUICtrlSetFont(-1, 11, 400, 0, "MS Sans Serif")
$DODInput = GUICtrlCreateDate("", 123, 68, 123, 21,(0x00))
$Button1 = GUICtrlCreateButton("Submit", 296, 77, 75, 25)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
$cEnterDummy = GUICtrlCreateDummy()
$cFileDummy = GUICtrlCreateDummy()
Local $aAccelKeys[2][2] = [["{ENTER}", $cEnterDummy],["^f", $cFileDummy]]
GUISetAccelerators($aAccelKeys)
GUISetOnEvent($GUI_EVENT_CLOSE, "closeGUI")

While 1
    Sleep(100)
WEnd

Func setState()
    GUICtrlSetState($DODLabel, (GUICtrlRead($Radio) = 1) ? $GUI_SHOW : $GUI_HIDE)
    GUICtrlSetState($DODInput, (GUICtrlRead($Radio) = 1) ? $GUI_SHOW : $GUI_HIDE)
EndFunc

Func closeGUI()
    Exit
EndFunc

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

PERFECT!

Thanks so much.

Can you point me to a tutorial that might explain this in a little more detail:

GUICtrlSetState($DODInput, (GUICtrlRead($DecedentsRadio) = 1) ? $GUI_SHOW : $GUI_HIDE)

I don't understand how exactly it works, I do this manually for a lot of my scripts (if variable = x then GUI show else Gui hide)

Edited by Jewtus
Link to comment
Share on other sites

  • Moderators

Jewtus,

 

Can you point me to a tutorial that might explain this in a little more detail:

Look in the Help file for "Ternary operator". :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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...