Jump to content

adding a scrollbar to a section of a gui


gcue
 Share

Recommended Posts

hello world!

i am trying to make a section of a gui scrollable to fit icons within the frame space allocated. the gui is resizable so if the icons don't fit then thats when the scrollbar should help, if the icons fit the scroll bar should disappear. i tried using Melba's UDF but have not been able to get it working.

i would also like to make it scroll vertically only not horizontally.

here is melba's udf

and below is the working example script

thanks in advance!!

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WINAPI.au3>
#include <StaticConstants.au3>
#include <array.au3>
#include "GUIScrollbars_Ex.au3"

Opt("GUIOnEventMode", 1)

Global $buttons[1][3]

$dGUI = GUICreate("test", 507, 440)

$dashboard_frame = GUICtrlCreateLabel("", 4, 120, 500, 274, BitOR($SS_CENTER, $SS_RIGHT, $SS_BLACKRECT, $SS_GRAYRECT, $SS_WHITERECT, $SS_BLACKFRAME, $SS_SUNKEN, $WS_CLIPSIBLINGS))
GUICtrlSetState(-1, $GUI_DISABLE)
GUICtrlSetResizing(-1, BitOR($GUI_DOCKHCENTER, $GUI_DOCKTOP))

GUISetStyle(BitOR($GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX, $WS_SIZEBOX))

GUICtrlCreateButton("Create", 10, 10, 50, 20)
GUICtrlSetOnEvent(-1, "CreateBtns")
GUICtrlSetResizing(-1, BitOR($GUI_DOCKLEFT, $GUI_DOCKTOP, $GUI_DOCKSIZE))

GUICtrlCreateButton("Delete", 70, 10, 50, 20)
GUICtrlSetOnEvent(-1, "DeleteBtns")
GUICtrlSetResizing(-1, BitOR($GUI_DOCKLEFT, $GUI_DOCKTOP, $GUI_DOCKSIZE))

GUISetState()

GUISetOnEvent($GUI_EVENT_RESIZED, "Resize")
GUISetOnEvent($GUI_EVENT_MAXIMIZE, "Resize")
GUISetOnEvent($GUI_EVENT_RESTORE, "Resize")

GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")

While 1
    Sleep(10)
WEnd

Func Resize()

    $window_position = WinGetPos($dGUI)

    If Not @error Then
        $window_x_position = $window_position[0]
        $window_y_position = $window_position[1]

        $window_width = $window_position[2]
        $window_height = $window_position[3]


        If $window_width < 507 And $window_height < 440 Then
            $window_width = 507
            $window_height = 440
        EndIf

        If $window_width < 507 Then
            $window_width = 507
        EndIf

        If $window_height < 440 Then
            $window_height = 440
        EndIf

        WinMove($dGUI, "", $window_x_position, $window_y_position, $window_width, $window_height)

        GUICtrlSetPos($dashboard_frame, 2, 120, $window_width - 12, $window_height - 200)

        CreateBtns()
    EndIf

EndFunc   ;==>Resize


Func CreateBtns()

    DeleteBtns()

    $frame_position = ControlGetPos("", "", $dashboard_frame)

    $frame_x = $frame_position[0]
    $frame_y = $frame_position[1]
    $frame_width = $frame_position[2]
    $frame_height = $frame_position[3]

    $iconsdrawn = 50

    ReDim $buttons[$iconsdrawn][3]

    $item_space = 65

    $startX = $frame_x + 10
    $startY = $frame_y + 10

    $allocated_width = $frame_width - 30
    $allocated_height = $frame_height - 20

    $horizontal_items = Floor($allocated_width / $item_space)
    $vertical_rows = Ceiling($iconsdrawn / $horizontal_items)

    $item_Y = $startY

    $item_count = 0

    For $p = 0 To $vertical_rows - 1
        $item_x = $startX

        For $m = 0 To $horizontal_items - 1
            If $item_count = $iconsdrawn Then ExitLoop

            $buttons[$item_count][0] = GUICtrlCreateCheckbox("", $item_x + 6, $item_Y + 13, 13, 13);$startX + $ButHor * $horPitch, $StartY + $ButVert * $VertPItch + 6, 13, 13)

            $buttons[$item_count][1] = GUICtrlCreateButton("", $item_x + 26, $item_Y + 6, 30, 30);$startX + $ButHor * $horPitch + 20, $StartY + $ButVert * $VertPItch, $ButWid, $ButHeight, $BS_ICON)

            $buttons[$item_count][2] = GUICtrlCreateLabel($item_count+1, $item_x + 5, $item_Y + 40, 60, 15);$startX + $ButHor * $horPitch - 10, $StartY + $ButVert * $VertPItch + $ButHeight + 6)

            $item_x += $item_space
            $item_count += 1
        Next
        $item_Y += $item_space
    Next

    _GUIScrollbars_Generate($dGUI, $frame_width, $frame_height)


EndFunc   ;==>CreateBtns

Func DeleteBtns()

    For $m = 0 To UBound($buttons)-1
        GUICtrlDelete($buttons[$m][0])
        GUICtrlDelete($buttons[$m][1])
        GUICtrlDelete($buttons[$m][2])
    Next

EndFunc   ;==>deletebtns

Func _Exit()
    Exit
EndFunc   ;==>_Exit
Link to comment
Share on other sites

  • Moderators

gcue,

Does this help? ;)

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

#include "GUIScrollbars_Ex.au3"

Opt("GUIOnEventMode", 1)

Global $aControlIDs[1][3]

; Create main GUI
$hGUI_Main = GUICreate("Test", 500, 440, -1, -1, BitOR($GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX, $WS_SIZEBOX))
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
GUISetOnEvent($GUI_EVENT_RESIZED, "Resize")

GUICtrlCreateButton("Create", 10, 10, 50, 20)
GUICtrlSetOnEvent(-1, "CreateBtns")

GUICtrlCreateButton("Delete", 70, 10, 50, 20)
GUICtrlSetOnEvent(-1, "DeleteBtns")

GUICtrlCreateLabel("Button Count", 200, 10, 100, 20)
$cInput = GUICtrlCreateInput(25, 300, 10, 50, 20)

; Create child GUI
$hGUI_Child = GUICreate("Child", 480, 270, 10, 120, $WS_CHILD, $WS_EX_CLIENTEDGE, $hGUI_Main)

GUISetState(@SW_SHOW, $hGUI_Child)
GUISetState(@SW_SHOW, $hGUI_Main)

While 1
    Sleep(10)
WEnd

Func _Exit()
    Exit
EndFunc

Func Resize()

    ; Get size of main GUI
    $aSize = WinGetClientSize($hGUI_Main)
    ; Resize Child
    WinMove($hGUI_Child, "", 10, 120, $aSize[0] - 20, $aSize[1] - 130)
    ; Redraw the buttons
    CreateBtns()

EndFunc

Func CreateBtns()

    DeleteBtns()

    ; How many buttons
    $iNumber = GUICtrlRead($cInput)
    ; Size array to fit
    Global $aControlIDs[$iNumber][3]

    ; Sizing info
    $iSpacing = 65

    ; Get size of child GUI
    $aChild = WinGetClientSize($hGUI_Child)
    ; How many rows and columns can we fit in
    $iHorz_Limit = Int($aChild[0] / $iSpacing)
    $iVert_Limit = Int($aChild[1] / $iSpacing)
    ; How may rows do we need
    $iRows_Required = Ceiling($iNumber / $iHorz_Limit
    ; Create scrollbatrs if needed
    If $iRows_Required > $iVert_Limit Then
        $aScroll = _GUIScrollbars_Generate($hGUI_Child, 0, $iRows_Required * $iSpacing, 0, 0, True)
    EndIf

    l; Create buttons
    GUISwitch($hGUI_Child)
    For $i = 0 To $iRows_Required - 1
        $iY = $i * $iSpacing
        For $j = 0 To $iHorz_Limit -1
            $iX = $j * $iSpacing
            ; Which button
            $iItem = $j + ($i * $iHorz_Limit)
            ; Have we created enough?
            If $iItem = $iNumber Then
                ExitLoop 2
            EndIf
            ; Create buttons
            $aControlIDs[$iItem][0] = GUICtrlCreateCheckbox("", $iX + 6, $iY + 13, 13, 13)
            $aControlIDs[$iItem][1] = GUICtrlCreateButton("", $iX + 26, $iY + 6, 30, 30)
            $aControlIDs[$iItem][2] = GUICtrlCreateLabel($iItem + 1, $iX + 5, $iY + 40, 60, 15)
        Next

    Next

EndFunc

Func DeleteBtns()

    For $m = 0 To UBound($aControlIDs) - 1
        For $n = 0 To 2
            GUICtrlDelete($aControlIDs[$m][$n])
        Next
    Next

EndFunc

We can code it to scroll horizontally as well - you just need to fix the horizontal limit. Give it a try and come back if you run into problems. :)

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

 

Link to comment
Share on other sites

  • Moderators

gcue,

Glad I could help. :)

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

 

Link to comment
Share on other sites

  • Moderators

gcue,

1. Scrollbar disappearing when not needed: :)

; Create scrollbatrs if needed
If $iRows_Required > $iVert_Limit Then
    _GUIScrollbars_Generate($hGUI_Child, 0, $iRows_Required * $iSpacing, 0, 0, True)
Else
    _GUIScrollBars_ShowScrollBar($hGUI_Child, $SB_VERT, False)
EndIf

2. I am not sure I understand the problem. There is never any whitespace within the child GUI - but there is whitespace between the buttons and the child. You can adjust this by changing the position of the child within the main GUI. Is that what you want? :huh:

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

 

Link to comment
Share on other sites

  • Moderators

gcue,

I understand now. :thumbsup:

Add this command at the top of the function:

Func CreateBtns()

    _GUIScrollbars_Scroll_Page($hGUI_Child, -1, 1) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

    DeleteBtns()

Now the scrollbars are reset to the top before we create the new buttons. :)

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

 

Link to comment
Share on other sites

works great!

and now i understand why the scroll bar remains when i hit delete..

hahah

i added teh line you gave me before to the deletebtns

_GUIScrollBars_ShowScrollBar($hGUI_Child, $SB_VERT, False)

thank you thank you again!

Link to comment
Share on other sites

  • Moderators

gcue,

now i understand why the scroll bar remains when i hit delete

You should always leave something for the student to discover for themselves! :graduated:

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

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...