ozymandius257 Posted February 24, 2021 Share Posted February 24, 2021 (edited) 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 March 1, 2021 by ozymandius257 Back up my hard drive? - I can't even find reverse gear. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 24, 2021 Moderators Share Posted February 24, 2021 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 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...
ozymandius257 Posted February 25, 2021 Author Share Posted February 25, 2021 (edited) @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 February 25, 2021 by ozymandius257 Back up my hard drive? - I can't even find reverse gear. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 25, 2021 Moderators Share Posted February 25, 2021 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 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...
mikell Posted February 25, 2021 Share Posted February 25, 2021 23 hours ago, ozymandius257 said: then I tried ControlMove, but that didn't work either expandcollapse popup#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 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