Quantcast
Channel: AutoIt v3 - General Help and Support
Viewing all articles
Browse latest Browse all 12506

Dynamic GUI Creation

$
0
0
Hi guys,
I'm try to create a gui can be create element by itself. This is what i have done:
[ autoit ]         
#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> Global $iCount = 1 ; Number 1 is used for basic element Global $Element_For_Column = 3 ; Max number of element for column Global $Max_Element = 9 ; Number of total element Global $Move_Top, $Move_Left, $hGUISize_Height, $hGUISize_Width, $Temp_iCount $hGUI = GUICreate("Dynamic GUI", 233, 107, -1, -1) $Label_A1 = GUICtrlCreateLabel("This is a label n°1", 8, 26, 90, 17) GUICtrlSetResizing(-1, BitOR($GUI_DOCKTOP, $GUI_DOCKLEFT, $GUI_DOCKSIZE)) $Input_A1 = GUICtrlCreateInput("", 8, 43, 161, 21) GUICtrlSetResizing(-1, BitOR($GUI_DOCKTOP, $GUI_DOCKLEFT, $GUI_DOCKSIZE)) $Button_A1 = GUICtrlCreateButton("1", 176, 41, 51, 25) GUICtrlSetResizing(-1, BitOR($GUI_DOCKTOP, $GUI_DOCKLEFT, $GUI_DOCKSIZE)) $Button_A2 = GUICtrlCreateButton("Check Input", 8, 72, 75, 25) GUICtrlSetResizing(-1, BitOR($GUI_DOCKTOP, $GUI_DOCKLEFT, $GUI_DOCKSIZE)) $Button_Minus = GUICtrlCreateButton("-", 176, 2, 19, 25) GUICtrlSetResizing(-1, BitOR($GUI_DOCKTOP, $GUI_DOCKLEFT, $GUI_DOCKSIZE)) $Button_Plus = GUICtrlCreateButton("+", 210, 2, 19, 25) GUICtrlSetResizing(-1, BitOR($GUI_DOCKTOP, $GUI_DOCKLEFT, $GUI_DOCKSIZE)) GUISetState(@SW_SHOW) While 1  $nMsg = GUIGetMsg()  Switch $nMsg   Case $GUI_EVENT_CLOSE    Exit   Case $Button_A1    GUICtrlSetData($Input_A1, "You have clicked button 1")   Case $Button_A2    _Test_Func($Input_A1)   Case $Button_Plus    _Add_Element()   Case $Button_Minus    Delete_Element()  EndSwitch WEnd Func _Test_Func($Value)  MsgBox(0, "Test", "This is the value of Input:" & @CRLF & GUICtrlRead($Value)) EndFunc   ;==>_Test_Func Func _Add_Element()  Local $Size = WinGetClientSize($hGUI, "")  Local $hGUISize_Height = 120, $hGUISize_Width = 250  $Temp_iCount += 1  $iCount += 1  $Move_Top += 90  If $Temp_iCount = $Element_For_Column Then   If $iCount <= $Max_Element Then    WinMove($hGUI, "", Default, Default, $Size[0] + $hGUISize_Width, Default)    _Middle($hGUI, "")    $Move_Top = "" ; reset top    $Move_Left += 240 ; create left vaule    $Temp_iCount = "" ; reset temp_element   EndIf  EndIf  If $iCount <= $Max_Element Then   If $iCount <= $Element_For_Column Then    GUICtrlCreateLabel("This is a label n°" & $iCount, 8, 26 + $Move_Top, 90, 17) ; how to set the varable name?    GUICtrlSetResizing(-1, BitOR($GUI_DOCKTOP, $GUI_DOCKLEFT, $GUI_DOCKSIZE))    GUICtrlCreateInput("", 8, 43 + $Move_Top, 161, 21)    GUICtrlSetResizing(-1, BitOR($GUI_DOCKTOP, $GUI_DOCKLEFT, $GUI_DOCKSIZE))    GUICtrlCreateButton($iCount, 176, 41 + $Move_Top, 51, 25)    GUICtrlSetResizing(-1, BitOR($GUI_DOCKTOP, $GUI_DOCKLEFT, $GUI_DOCKSIZE))    GUICtrlCreateButton("Check Input", 8, 72 + $Move_Top, 75, 25)    GUICtrlSetResizing(-1, BitOR($GUI_DOCKTOP, $GUI_DOCKLEFT, $GUI_DOCKSIZE))    WinMove($hGUI, "", Default, Default, Default, $Size[1] + $hGUISize_Height)    _Middle($hGUI, "")   Else    GUICtrlCreateLabel("This is a label n°" & $iCount, 8 + $Move_Left, 26 + $Move_Top, 90, 17) ; how to set the varable name?    GUICtrlSetResizing(-1, BitOR($GUI_DOCKTOP, $GUI_DOCKLEFT, $GUI_DOCKSIZE))    GUICtrlCreateInput("", 8 + $Move_Left, 43 + $Move_Top, 161, 21)    GUICtrlSetResizing(-1, BitOR($GUI_DOCKTOP, $GUI_DOCKLEFT, $GUI_DOCKSIZE))    GUICtrlCreateButton($iCount, 176 + $Move_Left, 41 + $Move_Top, 51, 25)    GUICtrlSetResizing(-1, BitOR($GUI_DOCKTOP, $GUI_DOCKLEFT, $GUI_DOCKSIZE))    GUICtrlCreateButton("Check Input", 8 + $Move_Left, 72 + $Move_Top, 75, 25)    GUICtrlSetResizing(-1, BitOR($GUI_DOCKTOP, $GUI_DOCKLEFT, $GUI_DOCKSIZE))   EndIf  EndIf EndFunc   ;==>_Add_Element Func Delete_Element()  ;??? EndFunc   ;==>Delete_Element Func _Middle(Const $win, Const $txt) ; Snippet Valuater - cdkid  Local Const $Size = WinGetClientSize($win, $txt)  Local Const $y = (@DesktopHeight / 2) - ($Size[1] / 2)  Local Const $x = (@DesktopWidth / 2) - ($Size[0] / 2)  Return WinMove($win, $txt, $x, $y) EndFunc   ;==>_Middle

1) The gui can create element but the size of the width is good only for the second element, then increase every 3°, 4° etc.
2) Buttons don't work because i don't know how to set in the While...WEnd and the realtive function
3) I don't know how to make the creation of 3 element for column until the $Max_Element is reached
4) I don't know how to delete group element ( except the first )

Thanks ;)

EDIT: Two solved by myself, two to go...with a little help? :D

Viewing all articles
Browse latest Browse all 12506

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>