Burgaud Posted April 29, 2021 Share Posted April 29, 2021 (edited) (since necroing old post is not allowed/recommended) With regards to Melba23's script #include <StaticConstants.au3> Const $iGUIWidth = 300 Const $iGUIHeight = 160 $sTempGUIMessage = " Correct!" & @CRLF & "520" & " ms" $hGui = GUICreate("Testing", $iGUIWidth, $iGUIHeight) GUISetFont(20) GUISetState() ; Create the label asking Windows to size it $cLabel = GUICtrlCreateLabel($sTempGUIMessage, -1, -1, Default, Default, $SS_CENTER) ; And get its size $aPos = ControlGetPos($hGUI, "", $cLabel) ; Calculate the position $iX = ($iGUIWidth - $aPos[2]) / 2 $iY = ($iGUIHeight - $aPos[3]) / 2 ; And move the label ControlMove($hGUI, "", $cLabel, $iX, $iY) GUICtrlSetBkColor(-1, 0xCCFFCC) Sleep(1000) Thought it manages to center a label vertically and horizontally, my concern is that, this is only valid for a static label. What if I altered the text on the label using GUICtrlSetData and the text will no longer be centered. Doing a ControlGetPos and ControlMove the 2nd time wont work. I need to center a Text (horizontally AND vertically) on a GUI (either it be Label, or otherwise). Text can be 1 liner, or 2 lines or more. And I need to be able to set font as well. Creating a label using: GUICtrlCreateLabel($text, -1, -1, Default, Default, 0x01) somehow negates font settings: GUICtrlSetFont ($gui, $lab, 400, 0, "Verdana", 5) Currently, I am thinking of constantly creating and deleting these Labels as needed. But creating and deleting as often as 100ms worries me. Edited April 29, 2021 by Burgaud Link to comment Share on other sites More sharing options...
caramen Posted April 29, 2021 Share Posted April 29, 2021 According to your issue described above. You could hide control maybe ? So you won't move them and break their status. I'm not sure but, maybe you could also try to redraw your GUI with _WinAPI_RedrawWindow($hGui) My video tutorials : ( In construction ) || My Discord : https://discord.gg/S9AnwHw How to Ask Help || UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote Spoiler Water's UDFs:Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsPowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & SupportExcel - Example Scripts - WikiWord - Wiki Tutorials:ADO - Wiki 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