TheDcoder Posted May 4, 2015 Share Posted May 4, 2015 (edited) Hello, Please look at this code:#include <WindowsConstants.au3> #include <GUIConstantsEx.au3> #include "StringSize.au3" For $i = 1 To 100 StatusIndicator("Really Loooooong Text", $i) Next Func StatusIndicator($sStatus, $sSize = 8.5, $hParent = 0) $aDimensions = _StringSize($sStatus, $sSize) $hGUI = GUICreate("", 50 + $aDimensions[2], 50 + $aDimensions[3], -1, -1, $WS_POPUP + $WS_BORDER, -1, $hParent) GUISetBkColor(0xFFFFFF) GUICtrlCreateLabel($sStatus, ((50 +$aDimensions[2]) - $aDimensions[2]) / 2, ((50 +$aDimensions[3]) - $aDimensions[3]) / 2, $aDimensions[2], $aDimensions[3], 0x01) GUICtrlSetFont(-1, $sSize) GUISetState() Sleep(250) EndFuncResult: (Fast Forwarded by 250 %)As you can see, the last word ("Text") is automatically shifting down, How can I prevent this? Thanks in Advance, TD Edited May 4, 2015 by TheDcoder Changed Title EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time) DcodingTheWeb Forum - Follow for updates and Join for discussion Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted May 4, 2015 Moderators Share Posted May 4, 2015 TheDcoder,I would increase the returned width parameter just a little:Func StatusIndicator($sStatus, $sSize = 8.5, $hParent = 0) $aDimensions = _StringSize($sStatus, $sSize) $iWidth = $aDimensions[2] * 1.05 ; Increase the width a tad $iHeight = $aDimensions[3] $hGUI = GUICreate("", 50 + $iWidth, 50 + $iHeight, -1, -1, $WS_POPUP + $WS_BORDER, -1, $hParent) GUISetBkColor(0xFFFFFF) GUICtrlCreateLabel($sStatus, ((50 + $iWidth) - $iWidth) / 2, ((50 +$iHeight) - $iHeight) / 2, $iWidth, $iHeight, 0x01) GUICtrlSetFont(-1, $sSize) GUISetState() Sleep(250) EndFuncIn my experience the UDF occasionally returns dimensions which are slightly too small (usually by a single pixel) for some larger font sizes with specific string lengths. Unfortunately I have never been able to find a reliable indicator of when this is likely to occur and so other than adding a random pixel or two to the returned value I cannot do anything about it.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...
BrewManNH Posted May 4, 2015 Share Posted May 4, 2015 With the style setting you used, $SS_CENTER, you can't prevent it, other than to size your label correctly. The stringsize UDF uses Tahoma font as the default, GUICtrlSetFont uses the default GUI font, but I'm not sure what that is.$SS_CENTER0x01Specifies a simple rectangle and centers the error value text in the rectangle. The control automatically wraps words that extend past the end of a line to the beginning of the next centered line.If you use the same font in StringSize and GUICtrlSetFont, it works fine.$aDimensions = _StringSize($sStatus, $sSize, Default, Default, "Segoe UI") GUICtrlSetFont(-1, $sSize, 400, 0, "Segoe UI") If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted May 4, 2015 Moderators Share Posted May 4, 2015 (edited) BrewManNH,Not entirely true - the UDF defaults to Tahoma if it cannot determine the system default, so the 2 should be the same. And even if I set the 2 fonts as you suggested, my system still shows the same symptoms. I might well have to amend the UDF to add a couple of pixels when using larger fonts to try and avoid this problem.M23Edit: Apologies - my error to suggest that the results were similar when the font was defined. But my comment about the odd sizing error still stands. Edited May 4, 2015 by Melba23 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...
BrewManNH Posted May 4, 2015 Share Posted May 4, 2015 I was going by what the header text stated, but in looking at the code I see where you call _StringSize_DefaultFontName to get the default name.Odd that the default comes back as Segoe UI, but the results are wrong if you don't specify Segoe UI in the GUICtrlSetFont statement. Maybe Segoe UI isn't being used as the actual default font, even though SystemParametersInfo says it is. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
UEZ Posted May 4, 2015 Share Posted May 4, 2015 That looks awful but you can try it this way:#include <WindowsConstants.au3> #include <GUIConstantsEx.au3> #include "StringSize.au3" $hParent = 0 $iX = @DesktopWidth / 2 $iY = @DesktopHeight / 2 $sText = "Really Loooooong Text" $aDimensions = _StringSize($sText, 8.5) $hGUI = GUICreate("", $aDimensions[2], $aDimensions[3], -1, -1, $WS_POPUP + $WS_BORDER, -1, $hParent) GUISetBkColor(0xFFFFFF) $iLabel = GUICtrlCreateLabel($sText, 0, 0, $aDimensions[2], $aDimensions[3], 0x201) GUISetState() For $i = 10 To 80 Step 0.5 StatusIndicator($sText, $i) Next Func StatusIndicator($sStatus, $sSize = 8.5, $hParent = 0) GUICtrlSetFont($iLabel, $sSize) $aDimensions = _StringSize($sStatus, $sSize) $iW = Int($aDimensions[2] * 1.15) $iH = Int($aDimensions[3] * 1.15) WinMove($hGUI, "", $iX - $iW / 2, $iY - $iH / 2, $iW, $iH) Sleep(10) EndFunc Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
TheDcoder Posted May 5, 2015 Author Share Posted May 5, 2015 Thanks @Melba23 EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time) DcodingTheWeb Forum - Follow for updates and Join for discussion 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