Jump to content

SOLVED - Resizing a list box


Recommended Posts

I am trying to make a list box resize it's height dependent on the number of items in it.

Currently I'm hard coding the size to change to, just as a proof of concept - eventually I'll change the size of the form as the list box expands - but it just doesn't seem to work.

I've hunted though examples in the forum, and tried WinMove, but that didn't work, and then I tried ControlMove, but that didn't work either.

Here's what I have currently - any help appreciated.

 

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

$frmMain = GUICreate("List box test", 244, 475, 192, 124)
$btnAddItems = GUICtrlCreateButton("Add items", 64, 24, 99, 33)
$lstThings = GUICtrlCreateList("", 32, 72, 161, 123)  ;L, T, W, H
GUISetState(@SW_SHOW)


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $btnAddItems
            _GUICtrlListBox_BeginUpdate($lstThings)
            _GUICtrlListBox_AddString($lstThings, "Dave")
            _GUICtrlListBox_AddString($lstThings, "Bert")
            _GUICtrlListBox_AddString($lstThings, "Harry")
            _GUICtrlListBox_EndUpdate($lstThings)
            $Count = _GUICtrlListBox_GetCount($lstThings)
            If $Count > 9 Then  ;increase the size of the list box
                GUIRegisterMsg($WM_SIZE, "MY_WM_SIZE")
            EndIf
    EndSwitch
WEnd

Func MY_WM_SIZE()
    ControlMove($frmMain, "", $lstThings, 32, 72, 161, 165)
    Return $GUI_RUNDEFMSG
EndFunc

 

Edited by ozymandius257

Back up my hard drive? - I can't even find reverse gear.

Link to comment
Share on other sites

  • Moderators

ozymandius257,

Why on earth are you using GUIRegisterMsg? Just use WinMove directly like this:

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

$frmMain = GUICreate("List box test", 244, 475, 192, 124)
$btnAddItems = GUICtrlCreateButton("Add items", 64, 24, 99, 33)
$lstThings = GUICtrlCreateList("", 32, 72, 161, 123)  ;L, T, W, H
GUISetState(@SW_SHOW)


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $btnAddItems
            _GUICtrlListBox_BeginUpdate($lstThings)
            _GUICtrlListBox_AddString($lstThings, "Dave")
            _GUICtrlListBox_AddString($lstThings, "Bert")
            _GUICtrlListBox_AddString($lstThings, "Harry")
            _GUICtrlListBox_EndUpdate($lstThings)
            $Count = _GUICtrlListBox_GetCount($lstThings)
            ConsoleWrite($Count & @CRLF)
            If $Count > 9 Then  ;increase the size of the list box
                WinMove(GUICtrlGetHandle($lstThings), "", Default, Default, 161, 300)
            EndIf
    EndSwitch
WEnd

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

@Melba23  ...because that's what the examples I found were using :) 

This is much easier - I guess it wasn't working because I wasn't using GUICtrlGetHandle when I tried WinMove.

Many thanks for a speedy reply.

 

- How do I go about marking this as solved? - I thought I could edit the title, but I don't seem to be able to.

Edited by ozymandius257

Back up my hard drive? - I can't even find reverse gear.

Link to comment
Share on other sites

  • Moderators

ozymandius257,

Those examples were probably resizing the listbox to match a resize of the GUI - then you do need to look for the Windows message telling you the GUI has changed.

If you edit the first post you should be able to edit the title of the thread.

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

23 hours ago, ozymandius257 said:

then I tried ControlMove, but that didn't work either

:blink:

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

$frmMain = GUICreate("List box test", 244, 475, 192, 124)
$btnAddItems = GUICtrlCreateButton("Add items", 64, 24, 99, 33)
$lstThings = GUICtrlCreateList("", 32, 72, 161, 123)  ;L, T, W, H
GUISetState(@SW_SHOW)


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $btnAddItems
            _GUICtrlListBox_BeginUpdate($lstThings)
            _GUICtrlListBox_AddString($lstThings, "Dave")
            _GUICtrlListBox_AddString($lstThings, "Bert")
            _GUICtrlListBox_AddString($lstThings, "Harry")
            _GUICtrlListBox_EndUpdate($lstThings)

             Sleep(1000)
            _GUICtrlListBox_BeginUpdate($lstThings)
           For $i = 0 to 8
                _GUICtrlListBox_AddString($lstThings, $i)
           Next
            _GUICtrlListBox_EndUpdate($lstThings)

            $Count = _GUICtrlListBox_GetCount($lstThings)
            ConsoleWrite($Count & @CRLF)
            If $Count > 9 Then  ;increase the size of the list box
             ;   WinMove(GUICtrlGetHandle($lstThings), "", Default, Default, 161, 300)
                ControlMove($frmMain, "", $lstThings, Default, Default, 161, 300)
            EndIf
    EndSwitch
WEnd

 

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...