johnmcloud Posted April 19, 2013 Posted April 19, 2013 (edited) Hi guys,I'm try to create a gui can be create element by itself. This is what i have done:expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> Opt("GUIResizeMode", BitOR($GUI_DOCKTOP, $GUI_DOCKLEFT, $GUI_DOCKSIZE)) Global Const $Element_For_Column = 5 ; Max number of element for column Global Const $Max_Element = 15 ; Number of total element Global $iCount = 1 ; Number 1 is used for basic element Global $Move_Top, $Move_Left, $Temp_iCount Global $Input_[1][1], $Label_[1][1], $Button_[1][2] $hGUI = GUICreate("Dynamic GUI", 233, 107, -1, -1) $Label_A1 = GUICtrlCreateLabel("This is a label n°1", 8, 26, 90, 17) $Input_A1 = GUICtrlCreateInput("", 8, 43, 161, 21) $Button_A1 = GUICtrlCreateButton("1", 176, 41, 51, 25) $Button_A2 = GUICtrlCreateButton("Check Input", 8, 72, 75, 25) $Button_Minus = GUICtrlCreateButton("-", 176, 2, 19, 25) $Button_Plus = GUICtrlCreateButton("+", 210, 2, 19, 25) GUISetState(@SW_SHOW) While 1 $msg = GUIGetMsg() Switch $msg 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() Case Else For $i = 0 To UBound($Button_, 1) - 1 Switch $msg Case $Button_[$i][0] GUICtrlSetData($Input_[$i][0], "You have clicked button " & $i + 1) Case $Button_[$i][1] _Test_Func($Input_[$i][0]) EndSwitch Next EndSwitch WEnd Func _Test_Func($Value) MsgBox(0, 0, "This is the value of Input: " & GUICtrlRead($Value) & @CRLF) EndFunc ;==>_Test_Func Func _Add_Element() Global $hGUISize_Height = 89, $hGUISize_Width = 250 Local Const $Size = WinGetPos($hGUI) $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[2] + $hGUISize_Width, Default) _Middle($hGUI, "") $Move_Top = 0 ; reset top $Move_Left += 250 ; create left vaule $Temp_iCount = 0 ; reset temp_element EndIf EndIf If $iCount <= $Max_Element Then ReDim $Label_[$iCount][$iCount] ReDim $Input_[$iCount][$iCount] ReDim $Button_[$iCount][$iCount * 2] If $iCount <= $Element_For_Column Then $Label_[$iCount - 1][0] = GUICtrlCreateLabel("This is a label n°" & $iCount, 8, 26 + $Move_Top, 90, 17) $Input_[$iCount - 1][0] = GUICtrlCreateInput("", 8, 43 + $Move_Top, 161, 21) $Button_[$iCount - 1][0] = GUICtrlCreateButton($iCount, 176, 41 + $Move_Top, 51, 25) $Button_[$iCount - 1][1] = GUICtrlCreateButton("Check Input", 8, 72 + $Move_Top, 75, 25) WinMove($hGUI, "", Default, Default, Default, $Size[3] + $hGUISize_Height) _Middle($hGUI, "") Else $Label_[$iCount - 1][0] = GUICtrlCreateLabel("This is a label n°" & $iCount, 8 + $Move_Left, 26 + $Move_Top, 90, 17) $Input_[$iCount - 1][0] = GUICtrlCreateInput("", 8 + $Move_Left, 43 + $Move_Top, 161, 21) $Button_[$iCount - 1][0] = GUICtrlCreateButton($iCount, 176 + $Move_Left, 41 + $Move_Top, 51, 25) $Button_[$iCount - 1][1] = GUICtrlCreateButton("Check Input", 8 + $Move_Left, 72 + $Move_Top, 75, 25) EndIf EndIf If $iCount > $Max_Element Then $iCount = $Max_Element $Temp_iCount = $Element_For_Column - 1 EndIf EndFunc ;==>_Add_Element Func Delete_Element() Local Const $Size = WinGetPos($hGUI) Local $Temp_Move_Top = 90 ; Equal to $Move_Top If $iCount = 1 Then ; No element $iCount = 1 Return Else GUICtrlDelete($Label_[$iCount - 1][0]) ; delete element GUICtrlDelete($Input_[$iCount - 1][0]) ; delete element GUICtrlDelete($Button_[$iCount - 1][0]) ; delete element GUICtrlDelete($Button_[$iCount - 1][1]) ; delete element EndIf If $iCount <> 0 Then If $iCount <= $Element_For_Column Then WinMove($hGUI, "", Default, Default, Default, $Size[3] - $hGUISize_Height) ; resize gui _Middle($hGUI, "") EndIf EndIf If $Temp_iCount = 0 Then ; New Column WinMove($hGUI, "", Default, Default, $Size[2] - $hGUISize_Width, Default) ; resize gui _Middle($hGUI, "") $Move_Left -= 250 ; Remove left value $Temp_iCount += $Element_For_Column ; Remove new colum EndIf $iCount -= 1 ; Delete one count $Temp_iCount -= 1; Delete one temp count If $Move_Top = 0 Then ; Equal to start posizion $Move_Top = $Temp_Move_Top * ($Element_For_Column - 1) Else $Move_Top -= 90 ; Delete one position EndIf 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 ;==>_Middle1) 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 function3) I don't know how to make the creation of 3 element for column until the $Max_Element is reached4) I don't know how to delete group element ( except the first )Thanks EDIT: No more to go, if someone has suggestion/improvement just ask Edited April 21, 2013 by johnmcloud
jaberwacky Posted April 20, 2013 Posted April 20, 2013 (edited) Try this and see if it aint what you want. expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> Opt("GUIResizeMode", BitOR($GUI_DOCKTOP, $GUI_DOCKLEFT, $GUI_DOCKSIZE)) Global Const $Element_For_Column = 3 ; Max number of element for column Global Const $Max_Element = 9 ; Number of total element Global $iCount = 1 ; Number 1 is used for basic element Global $Move_Top Global $Move_Left Global $Temp_iCount Global Const $hGUI = GUICreate("Dynamic GUI", 233, 107, -1, -1) Global Const $Label_A1 = GUICtrlCreateLabel("This is a label n°1", 8, 26, 90, 17) Global Const $Input_A1 = GUICtrlCreateInput("", 8, 43, 161, 21) Global Const $Button_A1 = GUICtrlCreateButton("1", 176, 41, 51, 25) Global Const $Button_A2 = GUICtrlCreateButton("Check Input", 8, 72, 75, 25) Global Const $Button_Minus = GUICtrlCreateButton("-", 176, 2, 19, 25) Global Const $Button_Plus = GUICtrlCreateButton("+", 210, 2, 19, 25) Global $ctrl_array[1][4] GUISetState(@SW_SHOWNORMAL) Global $msg = '' Do $msg = GUIGetMsg() Switch $msg 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() Case Else Global $ctrl_array_upbound = UBound($ctrl_array, 1) For $i = 0 To $ctrl_array_upbound - 1 Switch $msg Case $ctrl_array[$i][2] GUICtrlSetData($ctrl_array[$i][1], "You have clicked button " & $i + 1) Case $ctrl_array[$i][3] _Test_Func($ctrl_array[$i][1]) EndSwitch Next EndSwitch Until False Func _Test_Func(Const $Value) ConsoleWrite("This is the value of Input: " & GUICtrlRead($Value) & @crlf) EndFunc ;==>_Test_Func Func _Add_Element() Local Const $Size = WinGetClientSize($hGUI, '') $Temp_iCount += 1 $iCount += 1 $Move_Top += 90 If $Temp_iCount = $Element_For_Column Then If $iCount <= $Max_Element Then Local Const $hGUISize_Width = 250 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 ReDim $ctrl_array[$iCount][$iCount * 4] If $iCount <= $Element_For_Column Then $ctrl_array[$iCount - 1][0] = GUICtrlCreateLabel("This is a label n°" & $iCount, 8, 26 + $Move_Top, 90, 17) ; how to set the variable name? $ctrl_array[$iCount - 1][1] = GUICtrlCreateInput("", 8, 43 + $Move_Top, 161, 21) $ctrl_array[$iCount - 1][2] = GUICtrlCreateButton($iCount, 176, 41 + $Move_Top, 51, 25) $ctrl_array[$iCount - 1][3] = GUICtrlCreateButton("Check Input", 8, 72 + $Move_Top, 75, 25) Local Const $hGUISize_Height = 120 WinMove($hGUI, "", Default, Default, Default, $Size[1] + $hGUISize_Height) _Middle($hGUI, "") Else $ctrl_array[$iCount - 1][0] = GUICtrlCreateLabel("This is a label n°" & $iCount, 8 + $Move_Left, 26 + $Move_Top, 90, 17) ; how to set the varable name? $ctrl_array[$iCount - 1][1] = GUICtrlCreateInput("", 8 + $Move_Left, 43 + $Move_Top, 161, 21) $ctrl_array[$iCount - 1][2] = GUICtrlCreateButton($iCount, 176 + $Move_Left, 41 + $Move_Top, 51, 25) $ctrl_array[$iCount - 1][3] = GUICtrlCreateButton("Check Input", 8 + $Move_Left, 72 + $Move_Top, 75, 25) 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 I'll leave deleting them as an exercise for you. =) Edited April 20, 2013 by jaberwocky6669 Helpful Posts and Websites: AutoIt Wiki | Can't find what you're looking for on the Forum? My scripts: Guiscape | Baroque AU3 Code Formatter | MouseHoverCalltips | SciTe Customization GUI | ActiveWindowTrack Toy | Monitor Configuration UDF
johnmcloud Posted April 20, 2013 Author Posted April 20, 2013 Thanks, i have make some little change ( i have make 4 different array for every element ) and i have added the deleting func...but it's a little bugged The script is on the first post. Can you/someone check it out? Thanks
johnmcloud Posted April 20, 2013 Author Posted April 20, 2013 (edited) I have resolved the 99% of the problems with Delete_Element() ( i have updated the script on the first post ) i have only the lastWhen i created 6 element ( with 5 = Max element for column, so it created a new column with 1 element ) and i try to delete the 6° and recreate it, work fine and no problemsWhen i created 6 element ( with 5 = Max element for column, so it created a new column with 1 element ) and i try to delete the 6° and the 5° ( the result is only one column with four element ) and recreate the 5° again, i don't see anythingTips?EDIT: I have resolve the last problem, seems work fine now. Waiting for expert if the have improvement-suggestion on this script. Thanks Edited April 20, 2013 by johnmcloud
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