WRP Posted July 10, 2014 Share Posted July 10, 2014 I'm having trouble with labels that don't expand to fit their text. According the docs, this should work, but the bottom two labels are truncated. How does expansion work, in general? #include <GuiConstantsEx.au3> GUICreate("Label Width Test", 250, 120) GUICtrlCreateLabel("Five Four Three Two One", 5, 5) GUICtrlSetBkColor(-1, 0x50cc40) GUICtrlSetFont(-1, 10, 400, 0, "Arial") GUICtrlCreateLabel("Six Five Four Three Two One", 5, 35) GUICtrlSetBkColor(-1, 0x50cc40) GUICtrlSetFont(-1, 10, 400, 0, "Arial") GUICtrlCreateLabel("Five Four Three Two One", 5, 65) GUICtrlSetBkColor(-1, 0x50cc40) GUICtrlSetFont(-1, 10, 700, 0, "Arial") GUICtrlCreateLabel("Six Five Four Three Two One", 5, 95) GUICtrlSetBkColor(-1, 0x50cc40) GUICtrlSetFont(-1, 10, 700, 0, "Arial") GUISetState() While 1 $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Link to comment Share on other sites More sharing options...
Moderators Solution Melba23 Posted July 10, 2014 Moderators Solution Share Posted July 10, 2014 WRP,Welcome to the AutoIt forums. Expansion is based on the default GUI font - not the control itself. So if you set the GUI default to 10 point (rather then the normal 8.5) then you will see that the first 2 labels are correctly expanded:#include <GuiConstantsEx.au3> GUICreate("Label Width Test", 250, 120) GUISetFont(-1, 10, 400, 0, "Arial") GUICtrlCreateLabel("Five Four Three Two One", 5, 5) GUICtrlSetBkColor(-1, 0x50cc40) ;GUICtrlSetFont(-1, 10, 400, 0, "Arial") GUICtrlCreateLabel("Six Five Four Three Two One", 5, 35) GUICtrlSetBkColor(-1, 0x50cc40) ;GUICtrlSetFont(-1, 10, 400, 0, "Arial") GUICtrlCreateLabel("Five Four Three Two One", 5, 65) GUICtrlSetBkColor(-1, 0x50cc40) GUICtrlSetFont(-1, 10, 700, 0, "Arial") GUICtrlCreateLabel("Six Five Four Three Two One", 5, 95) GUICtrlSetBkColor(-1, 0x50cc40) GUICtrlSetFont(-1, 10, 700, 0, "Arial") GUISetState() While 1 $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE Exit EndSwitch WEndAs soon as the label font is not the default GUI font, the expansion no longer works. But you can use my StringSize UDF (look in my sig for the link) to correctly size text in any font face/size/attribute - which will let you correctly size the control regardless of the default font used by the GUI. I hope that helps - please ask again if you have any questions. 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...
czardas Posted July 10, 2014 Share Posted July 10, 2014 There may be some useful ideas in >this thread, if not for this particular project, then maybe in similar circumstances in the future. It's not the same thing, but it is related. In the code I posted, the only reason the constants were replaced was because, at the time, I didn't have time to test the code with the latest release of AutoIt. It will run as is. The original code is in the comments (includes are also needed - a little jigsaw puzzle). operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
WRP Posted July 11, 2014 Author Share Posted July 11, 2014 Expansion is based on the default GUI font - not the control itself. Thanks. Now it's clear what's happening. I'm trying to get a grip on coding GUIs with AutoIt. As far as I can tell, buttons and labels are the only things that change shape to fit their contents. Is that correct? Is there a way to have controls rearrange automatically? For example, if a button in a row of buttons changes size, then the buttons on the right shift to the right to make room. I guess for that to work, every other element would have to be subject to re-sizing/positioning. It looks like control positions are always hard-coded, but I wanted to make sure that I hadn't missed something. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted July 11, 2014 Moderators Share Posted July 11, 2014 WRP, Is there a way to have controls rearrange automatically?Not as far as I know. You can set controls to resize as the GUI changes size (GUICtrlSetResizing) but to amend the size of a row of buttons if one changes size is another kettle of fish. But take a look at my ExtMsgBox UDF. There is some code in there to resize buttons depending on the number of buttons required and the size of the text to contain within them - that might be of some use. Although the idea is to keep all the buttons at the same size rather than adjst their individual sizes. 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...
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