Jump to content

Recommended Posts

Hello everyone,

How to transform the code below into something dynamic? To add 'n' elements as panels with show/hide information and still work.

Tried to optimize the code as much as possible :

;INCLUDES

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

Opt("GUIOnEventMode", 1)

;ELEMENTS

$FORM = GUICreate("Example", 615, 192, -1, -1, -1, -1, 0)
$ELEMENT_1_INFO_CLICK = GUICtrlCreateLabel("Element 1 info", 16, 16, 87, 20)
$ELEMENT_1_INFO = GUICtrlCreateEdit("", 16, 48, 185, 33, $ES_WANTRETURN, 0)
$ELEMENT_2_INFO_CLICK = GUICtrlCreateLabel("Element 2 info", 16, 96, 87, 20)
$ELEMENT_2_INFO = GUICtrlCreateEdit("", 16, 128, 185, 33, $ES_WANTRETURN, 0)

;DESIGN

GUISetBkColor(0xFFFFFF, $FORM)
GUISetOnEvent($GUI_EVENT_CLOSE, _Exit, $FORM)
GUICtrlSetFont($ELEMENT_1_INFO_CLICK, 10, 400, 4, "Arial")
GUICtrlSetCursor($ELEMENT_1_INFO_CLICK, 0)
GUICtrlSetData($ELEMENT_1_INFO, StringFormat("ELEMENT 1 DETAILED INFO CHECK \r\nHIDDEN"))
GUICtrlSetOnEvent($ELEMENT_1_INFO_CLICK, '_ELEMENT_1_INFO_CLICK')
GUICtrlSetFont($ELEMENT_2_INFO_CLICK, 10, 400, 4, "Arial")
GUICtrlSetCursor($ELEMENT_2_INFO_CLICK, 0)
GUICtrlSetData($ELEMENT_2_INFO, StringFormat("ELEMENT 2 DETAILED INFO CHECK \r\nHIDDEN"))
GUICtrlSetOnEvent($ELEMENT_2_INFO_CLICK, '_ELEMENT_2_INFO_CLICK')

GUISetState(@SW_SHOW, $FORM)

While 1
WEnd

;FUNCTIONS

Func _Exit()
    Exit
EndFunc   ;==>_Exit

Func _ELEMENT_1_INFO_CLICK()
    If GUICtrlGetState($ELEMENT_1_INFO) = 96 Then
        GUICtrlSetState($ELEMENT_1_INFO, $GUI_SHOW)
        GUICtrlSetPos($ELEMENT_2_INFO_CLICK, 16, 96)
        GUICtrlSetPos($ELEMENT_2_INFO, 16, 128)
    ElseIf GUICtrlGetState($ELEMENT_1_INFO) = 80 Then
        GUICtrlSetState($ELEMENT_1_INFO, $GUI_HIDE)
        GUICtrlSetPos($ELEMENT_2_INFO_CLICK, 16, 48)
        GUICtrlSetPos($ELEMENT_2_INFO, 16, 78)
    EndIf
EndFunc   ;==>_ELEMENT_1_INFO_CLICK

Func _ELEMENT_2_INFO_CLICK()
    If GUICtrlGetState($ELEMENT_2_INFO) = 96 Then
        GUICtrlSetState($ELEMENT_2_INFO, $GUI_SHOW)
    ElseIf GUICtrlGetState($ELEMENT_2_INFO) = 80 Then
        GUICtrlSetState($ELEMENT_2_INFO, $GUI_HIDE)
    EndIf
EndFunc   ;==>_ELEMENT_2_INFO_CLICK

 

Many thanks.  :D

PS : Any tips making the code more compact and efficient would be cool. :) 

Link to comment
Share on other sites

Wouldn't that be better to use the more standardized approach of a TreeView ?  If you look at the example of _GUICtrlTreeView_Create, you will see how they create "n" leaves.

But if you insist on using your code, I would define an Array of elements that you could create in a loop and manage in a single function based on index of the array...

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