Eambo Posted January 2, 2020 Share Posted January 2, 2020 Howdy all, and happy new year to you! I have a form with a bunch of buttons, however those buttons can be removed by a *.ini file. At the moment when the buttons are hidden/deleted (I tried both!) it just leaves a blank space, whereas I'd ideally like the buttons to collapse into the empty space. Does anyone have any thoughts on the cleanest way of doing that? At the moment the buttons are all "hard coded" in positioning which may be the problem, but I'm not sure how to create a button otherwise. Thank you as always! 🙂 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 2, 2020 Moderators Share Posted January 2, 2020 Eambo, I would use an algorithm to draw the button positions and then run through the buttons that need to be drawn. Here is a short example of the sort of thing I mean: expandcollapse popup#include <GUIConstantsEx.au3> Global $cStart, $cEnd ; Simulate different buttons to be drawn Global $aArray_Full[] = ["Button 1", "Button 2", "Button 3", "Button 4", "Button 5", "Button 6", "Button 7", "Button 8", "Button 9"] Global $aArray_Less[] = ["Button 1", "Button 2", "Button 4", "Button 5", "Button 6", "Button 8", "Button 9"] ; This bit is only needed to show the dymanic change Global $fFull = True $aDisplay = $aArray_Full $hGUI = GUICreate("Test", 300, 300) $cChange = GUICtrlCreateButton("Change", 110, 210, 80, 30) _DrawButtons() GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $cChange ; Delete exiting buttons For $i = $cStart To $cEnd GUICtrlDelete($i) Next ; Adjust input arrays Switch $fFull Case True $aDisplay = $aArray_Less Case False $aDisplay = $aArray_Full EndSwitch $fFull = Not($fFull) ; draw the new buttons _DrawButtons() EndSwitch WEnd Func _DrawButtons() $cStart = GUICtrlCreateDummy() ; Set the bounds of the buttons to delete later For $i = 0 To UBound($aDisplay) - 1 ; Run through the buttons to draw ; Determine the position of the next button $iX = (Mod($i, 3) * 100) + 10 ; Move over 3 times... $iY = (Int($i / 3) * 50) + 10 ; ...and then move down a row GUICtrlCreateButton($aDisplay[$i], $iX, $iY, 80, 30) Next $cEnd = GUICtrlCreateDummy() ; Same here EndFunc Please ask if you have any questions. M23 Eambo 1 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...
Eambo Posted January 2, 2020 Author Share Posted January 2, 2020 Very smart M23, thank you for the example! (Sorry I didn't post my code, it's a mess of additional stuff right now. Was trying to cut it down to post here but didn't get that far yet!) I'll see if I can make this idea work within my code and come back with any issues. Thank you again! 🙂 Link to comment Share on other sites More sharing options...
Nine Posted January 3, 2020 Share Posted January 3, 2020 (edited) @Eambo Instead of creating / deleting / creating /deleting buttons, you could simply change buttons name and hide the unused buttons. expandcollapse popup#include <GUIConstants.au3> ; Simulate different buttons to be drawn Const $aArray_Full[] = ["Button 1", "Button 2", "Button 3", "Button 4", "Button 5", "Button 6", "Button 7", "Button 8", "Button 9"] Const $aArray_Less[] = ["Button 1", "Button 2", "Button 4", "Button 5", "Button 6", "Button 8", "Button 9"] Local $hGui = GUICreate('Button test', 300, 300) Global $aButton[UBound($aArray_Full)], $iNum = 0 ;create buttons once For $y = 0 To 2 For $x = 0 To 2 $aButton[$iNum] = GUICtrlCreateButton($aArray_Full[$iNum], 10 + $x * 90, 10 + $y * 30, 85, 25) $iNum += 1 Next Next $cChange = GUICtrlCreateButton("Change", 110, 210, 80, 30) GUISetState() Local $fFull = True While 1 $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE Exit Case $aButton[0] To $aButton[UBound($aButton)-1] MsgBox(0, 'Button', 'No. ' & GUICtrlRead($msg) & ' was clicked', 0, $hGui) Case $cChange $fFull = Not $fFull _DrawButtons($fFull ? $aArray_Full : $aArray_Less) ; switch list of buttons EndSwitch WEnd Func _DrawButtons($aName) For $i = 0 To UBound($aName) - 1 ; Run through the buttons to draw GUICtrlSetData($aButton[$i], $aName[$i]) GUICtrlSetState($aButton[$i], $GUI_SHOW + $GUI_ENABLE) Next For $i = UBound($aName) To UBound($aButton) - 1 ; disable unused buttons GUICtrlSetState($aButton[$i], $GUI_HIDE + $GUI_DISABLE) Next EndFunc ;==>_DrawButtons Edited January 3, 2020 by Nine “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...
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