Jump to content
Eambo

GUI Button Resize/Repositioning Help

Recommended Posts

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! ūüôā

Share this post


Link to post
Share on other sites

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:

#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


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

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! ūüôā

Share this post


Link to post
Share on other sites
Posted (edited)

@Eambo Instead of creating / deleting / creating /deleting buttons, you could simply change buttons name and hide the unused buttons.

#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 by Nine

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...