Jump to content

help with hiding and unhiding a group control


Recommended Posts

hi guys i am trying to have group2 be hidden by default then for me to unhide it when the checkbox is checked. can someone help me with where i'm going wrong please?

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form2 = GUICreate("Form2", 413, 298, 302, 218)
$Group1 = GUICtrlCreateGroup("Group1", 24, 16, 249, 153)
$Group2 = GUICtrlCreateGroup("Group2", 72, 64, 169, 89)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUICtrlSetState(-1, $GUI_HIDE)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Checkbox1 = GUICtrlCreateCheckbox("UnHide group 2", 296, 80, 97, 17)
GUICtrlSetState(-1, $GUI_UNCHECKED)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $Checkbox1
            UNHIDE()
    EndSwitch
WEnd

Func UNHIDE()
    GUISetState($GUI_SHOW, $Group2)
EndFunc   ;==>UNHIDE
Link to comment
Share on other sites

I have modified your code somewhat, see the difference?

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form2 = GUICreate("Form2", 413, 298, 302, 218)
$Group1 = GUICtrlCreateGroup("Group1", 24, 16, 249, 153)
$Group2 = GUICtrlCreateGroup("Group2", 72, 64, 169, 89)
;GUICtrlCreateGroup("", -99, -99, 1, 1)
GUICtrlSetState(-1, $GUI_HIDE)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Checkbox1 = GUICtrlCreateCheckbox("UnHide group 2", 296, 80, 97, 17)
GUICtrlSetState(-1, $GUI_UNCHECKED)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $Checkbox1
            UNHIDE()
    EndSwitch
WEnd

Func UNHIDE()
    ;GUISetState($GUI_SHOW, $Group2)
    GUICtrlSetState($Group2, $GUI_SHOW)
EndFunc   ;==>UNHIDE

- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Link to comment
Share on other sites

I have modified your code somewhat, see the difference?

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form2 = GUICreate("Form2", 413, 298, 302, 218)
$Group1 = GUICtrlCreateGroup("Group1", 24, 16, 249, 153)
$Group2 = GUICtrlCreateGroup("Group2", 72, 64, 169, 89)
;GUICtrlCreateGroup("", -99, -99, 1, 1)
GUICtrlSetState(-1, $GUI_HIDE)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Checkbox1 = GUICtrlCreateCheckbox("UnHide group 2", 296, 80, 97, 17)
GUICtrlSetState(-1, $GUI_UNCHECKED)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $Checkbox1
            UNHIDE()
    EndSwitch
WEnd

Func UNHIDE()
    ;GUISetState($GUI_SHOW, $Group2)
    GUICtrlSetState($Group2, $GUI_SHOW)
EndFunc   ;==>UNHIDE

yes it works thanks.

so how do i hide it again if i uncheck the checkbox? like toggle. (please don't be mad for me asking) this is my 4th day learning Autoit :idea:

edit:

never mind i got it to do what i wanted. here is the solved code:

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form2 = GUICreate("Form2", 413, 298, 302, 218)
$Group1 = GUICtrlCreateGroup("Group1", 24, 16, 249, 153)
$Group2 = GUICtrlCreateGroup("Group2", 72, 64, 169, 89)
;GUICtrlCreateGroup("", -99, -99, 1, 1)
GUICtrlSetState(-1, $GUI_HIDE)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Checkbox1 = GUICtrlCreateCheckbox("UnHide group 2", 296, 80, 97, 17)
GUICtrlSetState(-1, $GUI_UNCHECKED)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $Checkbox1
            UNHIDE()
    EndSwitch
WEnd

Func UNHIDE()
    If GUICtrlRead($Checkbox1) = $GUI_CHECKED Then
        ;GUISetState($GUI_SHOW, $Group2)
        GUICtrlSetState($Group2, $GUI_SHOW)
    Else
        GUICtrlSetState($Group2, $GUI_HIDE)
    EndIf ;==>UNHIDE
EndFunc   ;==>UNHIDE
Edited by Tiboi
Link to comment
Share on other sites

Change the function UNHIDE() to this.

Func UNHIDE()
    If GUICtrlGetState($Group2) = 96 Then
        GUICtrlSetState($Group2, $GUI_SHOW)
    Else
        GUICtrlSetState($Group2, $GUI_HIDE)
    EndIf
EndFunc   ;==>UNHIDE

- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Link to comment
Share on other sites

Two different ways to do it, there's more I'm sure, so a new problem: which to use? :idea:

lol thanks for the help man i appreciate it. oh and where can i find the a list of controlID(s) Edited by Tiboi
Link to comment
Share on other sites

somdcomputerguy i have 2 questions: 1. where can i find the a list of controlIDs, cause i'd like to know how you got 96 in

If GUICtrlGetState($Group2) = 96 Then

2. how do i get controls in group2 to hide as well. eg. if i add a textbox to group2

Edited by Tiboi
Link to comment
Share on other sites

Here's a new UNHIDE()

Func UNHIDE()
    If GUICtrlGetState($Group2) = 96 Then
        GUICtrlSetState($Group2, $GUI_SHOW)
        ConsoleWrite(GUICtrlGetState($Group2) & @LF)
    Else
        GUICtrlSetState($Group2, $GUI_HIDE)
        ConsoleWrite(GUICtrlGetState($Group2) & @LF)
    EndIf
EndFunc   ;==>UNHIDE

AFAIK, any controls in a hidden group will be hidden as well. If not, I suppose they could be hidden/shown individually..

- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Link to comment
Share on other sites

here is the code, it does not hide tne control inside the group

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=C:\Documents and Settings\Administrator\Desktop\Form2.kxf
$Form2 = GUICreate("Form2", 414, 299, 302, 218)
$Group1 = GUICtrlCreateGroup("Group1", 24, 16, 249, 153)
$Group2 = GUICtrlCreateGroup("Group2", 56, 64, 169, 89)
$Input2 = GUICtrlCreateInput("Input2", 72, 104, 121, 21)
;GUICtrlCreateGroup("", -99, -99, 1, 1)

$Input1 = GUICtrlCreateInput("Input1", 40, 32, 121, 21)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Checkbox1 = GUICtrlCreateCheckbox("UnHide group 2", 296, 80, 97, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $Checkbox1
            UNHIDE()
    EndSwitch
WEnd

;Func UNHIDE()  <-- my code
;   If GUICtrlRead($Checkbox1) = $GUI_CHECKED Then
;       GUICtrlSetState($Group2, $GUI_SHOW)
;   Else
;       GUICtrlSetState($Group2, $GUI_HIDE)
;   EndIf
;EndFunc   ;==>UNHIDE

;Func UNHIDE()  <--somdcomputerguy code 1
;   If GUICtrlGetState($Group2) = 96 Then
;       GUICtrlSetState($Group2, $GUI_SHOW)
;   Else
;       GUICtrlSetState($Group2, $GUI_HIDE)
;   EndIf
;EndFunc   ;==>UNHIDE

Func UNHIDE() ;<--somdcomputerguy code 2
    If GUICtrlGetState($Group2) = 96 Then
        GUICtrlSetState($Group2, $GUI_SHOW)
        ConsoleWrite(GUICtrlGetState($Group2) & @LF)
    Else
        GUICtrlSetState($Group2, $GUI_HIDE)
        ConsoleWrite(GUICtrlGetState($Group2) & @LF)
    EndIf
EndFunc   ;==>UNHIDE
Link to comment
Share on other sites

  • Moderators

Tiboi,

You have to hide/show each control individually. If you create the controls in IMMEDIATE succession, you can do it like this: :idea:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

#Region ### START Koda GUI section ### Form=C:\Documents and Settings\Administrator\Desktop\Form2.kxf
$Form2 = GUICreate("Form2", 414, 299, 302, 218)
$Group1 = GUICtrlCreateGroup("Group1", 24, 16, 249, 153)
    $Input1 = GUICtrlCreateInput("Input1", 40, 32, 121, 21)
$Group2 = GUICtrlCreateGroup("Group2", 56, 64, 169, 89)
    $Input2 = GUICtrlCreateInput("Input2", 72, 104, 121, 21)
$GroupEnd = GUICtrlCreateGroup("", -99, -99, 1, 1)
; Hide Group2 to start
Group_Display($Group2, $GroupEnd, $GUI_HIDE)

$Checkbox1 = GUICtrlCreateCheckbox("UnHide group 2", 296, 80, 97, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $Checkbox1
            If GUICtrlRead($Checkbox1) = 1 Then
                Group_Display($Group2, $GroupEnd, $GUI_SHOW)
            Else
                Group_Display($Group2, $GroupEnd, $GUI_HIDE)
            EndIf
    EndSwitch
WEnd


Func Group_Display($iStart, $iEnd, $iState)

    For $i = $iStart To $iEnd
        GUICtrlSetState($i, $iState)
    Next

EndFunc

I hope it is clear what is going on - please ask if not. :)

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