_Vlad Posted December 1, 2019 Share Posted December 1, 2019 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 : expandcollapse popup;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. PS : Any tips making the code more compact and efficient would be cool. Link to comment Share on other sites More sharing options...
Nine Posted December 1, 2019 Share Posted December 1, 2019 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... _Vlad 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
_Vlad Posted December 1, 2019 Author Share Posted December 1, 2019 I will check that and come back with an answer. 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