Jump to content

Recommended Posts

Posted

Can someone confirm that GuiCtrlCreateLabel does not calculate the correct height, when the height parameter is omitted (allowing the function to calculate the required height) and the width of the text string causes word wrapping.

I find the description of the height parameter a bit unclear, but believe it should calculate the correct height if the height parameter is omitted, is –1, or is Default.  It does so when a multi-line string (one containing @LF to avoid word wrapping), is used, but not if word wrapping occurs.

Here’s a simple GUI demonstrating this issue:

 

#include <GUIConstants.au3>

GUICreate("Automatic Height issue with GUI Labels", 500, 380, -1, -1)

$iY = 10
$sText = "When the height parameter for a GUI Label is not specified, or set to -1, or Default, the height " & @LF & _
     "of the label is incorrect when word wrapping occurs.  The height does not take into account " & @LF & _
     "the number of lines added by the word wrapping!  Below are examples demonstrating this" & @LF & _
     "issue, what the label should look like ( @LF is used to avoid word wrapping )." & @LF & _
      @LF & _
      "The doc for GUICtrlCreateLabel says what follows for the height parameter:"
GUICtrlCreateLabel($sText, 10, $iY, 450, Default)
$iY += 80
GUICtrlCreateLabel("    height, [optional] The height of the control (default text autofit in height)", 10, $iY, 450, Default)
GUICtrlSetFont(-1, -1, 600)
GUICtrlSetColor(-1, 0x0000ff)


$iY += 60
GUICtrlCreateLabel("Word Wrap Example (label height is incorrect)", 10, $iY, 450, Default, $SS_Center)
GUICtrlSetFont(-1, 12, 600)
GUICtrlSetColor(-1, 0xff0000)
$iY += 20
;; Word Wrap example:
$sText = "This is an example showing that when the height parameter of a GuiCtlrCreateLabel " & _
     "is set to -1, or left as optional, the height of the control does not take word " & _
     "wrap into consideration, producing an incorrect height for the string."
GUICtrlCreateLabel($sText, 10, $iY, 450, Default)
GUICtrlSetBkColor(-1, 0xffff00)


$iY += 40
GUICtrlCreateLabel("What the above should show (@LF used)", 10, $iY, 450, Default, $SS_Center)
GUICtrlSetFont(-1, 12, 600)
GUICtrlSetColor(-1, 0x0000ff)
$iY += 20
$sText = "This is an example showing that when the height parameter of a GuiCtlrCreateLabel is set to -1," & @LF & _
     "or left as optional, the height of the control does not take word wrap into consideration," & @LF & _
     "producing an incorrect height for the string."
GUICtrlCreateLabel($sText, 10, $iY, 450, Default)
GUICtrlSetBkColor(-1, 0xffff00)


$iY += 90
$sText = "While the height produced when @LF is used to avoid word wrapping does not cut off text, " & @LF & _
     "the height is a little too large by about 1/2 line height."
GUICtrlCreateLabel($sText, 10, $iY, 450, Default)


GUISetState(@SW_SHOW)
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
Exit

 

  • Moderators
Posted (edited)

ILLBeBack,

You are correct - if not specified the vertical size of a label is set to fit the apparent lines of text, that is the number of EOLs . So if wrapping occurs because the width is not large enough the height will not be correct.

But you can use my StringSize UDF (look in my sig for the link) to determine the required dimensions for a control to fit any defined text at any size in any font.

M23

Edited by Melba23
Some words appear to have been left out on posting

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

 

Posted

ILLBeBack,

You are correct - if not specified the vertical size of a label is set to fit the apparent lines of text, that is the number of EOLs . So if wrapping occur the width will not be correct.

But you can use my StringSize UDF (look in my sig for the link) to determine the required dimensions for a control to fit any defined text at any size in any font.

M23

Thanks M23!  I'll look at your StringSize UDF later tonight!

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
×
×
  • Create New...