wisem2540 Posted July 9, 2013 Share Posted July 9, 2013 (edited) expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <File.au3> #include <Array.au3> #include <GuiScrollBars.au3> #include <GUIScrollbars_Ex.au3> #include <ScrollBarConstants.au3> Opt("GUIOnEventMode", 1) $Files = _FileListToArray (@ScriptDir & "\thumbnails", "*", 1); list all files to array in this dir ;_ArrayDisplay ($Files); display for debugging $hWnd = GUICreate("My Pics", 800,700); create a GUI GUISetOnEvent($GUI_EVENT_CLOSE, "Close"); if gui Closes Global $pic[150], $start = 20, $z = 20; variable to set position of thumbnails Global $Button[150]; buttons For $i = 1 to $Files[0]; for the number of files in the dir $pic[$i] = GUICtrlCreatePic(@ScriptDir & "\thumbnails\" & $Files[$i], $start, $z, 134, 193); send pics to GUI $Button[$i] = GUICtrlCreateButton ("Download " & $i, $start + 40, $z + 200); send download buttons GUICtrlSetOnEvent($Button[$i], "Download"); if download is clicked $start = $start + 150; add 150 to position If $start > 700 Then; if position is greater than 700 $Z = $z + 275; add to this position to start new row $start = 10; start horizontal position back at 10 for new row EndIf Next _GUIScrollbars_Generate($hWnd, 1000, $z); create scroll bars using Z, the largest vertical position GUISetState(@SW_SHOW); show GUI _ArrayDisplay ($Button); show array of buttons for debugging While 1 WEnd Func Download() MsgBox (0, "test", " You Clicked " ) EndFunc Func Close() Exit EndFunc In this scenario, I have 20 files in the dir, which I will attach here. I can loop through 1-20 just fine it seems, even creating download buttons 1-20. However, when I use the $i variable to assign names to the buttons and pictues, they only number every other one. The pics go 1-3-5-7 and the buttons go 2-4-6-8. Im sure there is a simple explaination why, but im not seeing it. In the end, they all need to relate somehow. So if I click download button 1, it downloads movie 1 and so on. For now, I am content using message boxes for demonstration. Thumbnails.zip Edited July 9, 2013 by wisem2540 Link to comment Share on other sites More sharing options...
FireFox Posted July 9, 2013 Share Posted July 9, 2013 Hi,The numbers stored in the Button and pic arrays are control IDs and they are internally generated.It begins from 3 and is incremented each time you create a control.Br, FireFox. Link to comment Share on other sites More sharing options...
wisem2540 Posted July 9, 2013 Author Share Posted July 9, 2013 well that explains one piece of the puzzle. But one thing I do not Understand is.... If I have a For loop. For $X= 1 to 5 $Button[$x] = Createbutton next What I am trying to accomplish is Button1, Button2, Button3, Button4, Button5. So I tried $Button & $x = Createbutton, and I get an error. Is this possible to accomplish? Would I be better off, since I am trying to make all of these controls to relate, to read all of the data to one array? Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted July 9, 2013 Moderators Share Posted July 9, 2013 wisem2540,Your loop should work - you are using the loop variable as the index to the array. So your array will look like this:Index Content 0 Unused 1 ControlID of Button1 (= 2) 2 ControlID of Button2 (= 4) 3 ControlID of Button3 (= 6) 4 ControlID of Button4 (= 8) 5 ControlID of Button5 (= 10) etc....To find out which button you pressed, I would do something like this (look for the <<<<<<<<< lines):expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <File.au3> #include <Array.au3> #include <GUIScrollbars_Ex.au3> Opt("GUIOnEventMode", 1) Global $pic[150], $start = 20, $z = 20; variable to set position of thumbnails Global $Button[150]; buttons ;$Files = _FileListToArray(@ScriptDir & "\thumbnails", "*", 1); list all files to array in this dir ;_ArrayDisplay ($Files); display for debugging $hWnd = GUICreate("My Pics", 800, 700); create a GUI GUISetOnEvent($GUI_EVENT_CLOSE, "Close"); if gui Closes For $i = 1 To 100 ; Used as an example $Files[0]; for the number of files in the dir ;$pic[$i] = GUICtrlCreatePic(@ScriptDir & "\thumbnails\" & $Files[$i], $start, $z, 134, 193); send pics to GUI $pic[$i] = GUICtrlCreateLabel("", $start, $z, 134, 193); use labels as I do not have images <<<<<<<<<<<<<<<<<<< <<<<<<<<<<<<<<< GUICtrlSetBkColor(-1, 0xFFCCFF) ; And colour them so they are visible <<<<<<<<<<<<<< $Button[$i] = GUICtrlCreateButton("Download " & $i, $start + 40, $z + 200); send download buttons GUICtrlSetOnEvent($Button[$i], "Download"); if download is clicked $start = $start + 150; add 150 to position If $start > 700 Then; if position is greater than 700 $z = $z + 275; add to this position to start new row $start = 10; start horizontal position back at 10 for new row EndIf Next _GUIScrollbars_Generate($hWnd, 1000, $z); create scroll bars using Z, the largest vertical position GUISetState(@SW_SHOW); show GUI _ArrayDisplay($Button); show array of buttons for debugging While 1 Sleep(10) ; Important to have a Sleep here or you risk frying the CPU <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< WEnd Func Download() ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ; Which button was pressed? $iButtonID = @GUI_CtrlId ; Now find it in the array $iIndex = _ArraySearch($Button, $iButtonID) If $iIndex <> -1 Then MsgBox(0, "test", " You Clicked " & $iIndex) EndIf EndFunc ;==>Download Func Close() Exit EndFunc ;==>CloseAnd that same index will correspond to the images in their array - so it will be easy to get the path. Does all that make sense? Please ask if not. M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
wisem2540 Posted July 9, 2013 Author Share Posted July 9, 2013 Melba, yes it makes sense. I added a MsgBox(0, "test", " You Clicked " & $Files [$iIndex]) this way I can see the filename as well. I assune this is a safe practice? thanks for your help Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted July 9, 2013 Moderators Share Posted July 9, 2013 wisem2540, I assune this is a safe practice?Would I have suggested it if it were not? M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
wisem2540 Posted July 9, 2013 Author Share Posted July 9, 2013 I was referring to my assuming that the index number would always also match up to the files array, but it seems to work. Thanks again Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted July 9, 2013 Moderators Share Posted July 9, 2013 wisem2540,As lomg as you create the images and the buttons as you are now (both in the same loop) the index will match in both arrays. M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area 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