Jump to content

Search the Community

Showing results for tags 'vertical center'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • General
    • Announcements and Site News
    • Administration
  • AutoIt v3
    • AutoIt Help and Support
    • AutoIt Technical Discussion
    • AutoIt Example Scripts
  • Scripting and Development
    • Developer General Discussion
    • Language Specific Discussion
  • IT Administration
    • Operating System Deployment
    • Windows Client
    • Windows Server
    • Office

Categories

  • AutoIt Team
    • Beta
    • MVP
  • AutoIt
    • Automation
    • Databases and web connections
    • Data compression
    • Encryption and hash
    • Games
    • GUI Additions
    • Hardware
    • Information gathering
    • Internet protocol suite
    • Maths
    • Media
    • PDF
    • Security
    • Social Media and other Website API
    • Windows
  • Scripting and Development
  • IT Administration
    • Operating System Deployment
    • Windows Client
    • Windows Server
    • Office

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Member Title


Location


WWW


Interests

Found 1 result

  1. Suppose we want to put a text of variable lengths in the vertical center of two horizontal lines. The text is mostly one liner, but some are so long that they have to be wrapped to 2 lines. Unfortunately, GUICtrlCreateLabel() doesn't have a style option for vertical centering of the text. $SS_CENTERIMAGE works, but it does not allow wrapping. I thought I could adjust the vertical position of the label control if I know the text is wrapped. But I could not find a function to determine if the text is wrapped or not. StringSize UDF is too good and too cumbersome for this small purpose. Creating a temporary, hidden label control was the solution. It takes 4 to 6 milliseconds, which is about the same as, or a little faster than, StringSize UDF. HotKeySet("{ESC}", "Quit") local $hGUI = GUICreate("Vertical Center", 290, 200, -1, -1) GUISetFont(12, 400) Local $sLine = "-----------------------------------" Local $sShort = "A short string of characters" Local $sLong_1 = "A long string of characters in ORIGINAL label position" Local $sLong_2 = "A long string of characters in ADJUSTED label position" Local $iLabelWidth = 250 Local $idLabel_1 = GUICtrlCreateLabel($sLine, 20, 20, $iLabelWidth, 20) Local $idLabel_2 = GUICtrlCreateLabel($sShort, 20, 48, $iLabelWidth, 35) Local $idLabel_3 = GUICtrlCreateLabel($sLine, 20, 80, $iLabelWidth, 20) GUISetState() Local $sString = $sShort, $tmpGUI, $tmpLabel, $aPos While 1 ; The next 4 lines of code calculate the pixel width of a string. $tmpGUI = GUICreate("") GUISetFont(12, 400) ; keep font the same as main GUI $tmpLabel = GUICtrlCreateLabel($sString, 0, 0) $aPos = ControlGetPos($tmpGUI, "", $tmpLabel) GUIDelete($tmpGUI) If $aPos[2] <= $iLabelWidth Then ; text is one liner $sString = $sShort GUICtrlSetData($idLabel_2, $sString) GUICtrlSetPos($idLabel_2, 20, 48) $sString = $sLong_1 Else ; text is wrapped GUICtrlSetData($idLabel_2, $sString) Sleep(5000) $sString = $sLong_2 GUICtrlSetData($idLabel_2, $sString) GUICtrlSetPos($idLabel_2, 20, 40) $sString = $sShort EndIf Sleep(5000) WEnd Func Quit() GUIDelete($hGUI) Exit EndFunc
×
×
  • Create New...