VocabMike Posted January 13 Share Posted January 13 (edited) Got bored over Christmas so... any use to anyone? expandcollapse popup#include <GUIConstantsEx.au3> #include <GuiListView.au3> ; ============ Test Strings ================== ;$sText = "Please Visually Confirm Transfer..." & @CRLF & @CRLF & "A Total of >> " & StringFormat("%d", 99.999) & " << " & "jpg" & " Files were Copied..." ;Local $sText = "C:\This\Is\A\Very\Long\Path\That\DOSE NOT Needs\To\Wrap\To\A\New\Line\Filename.txt" Local $sText = "Mike is off to town" ;Local $sText = "Mike is off to town" & @crlf & "Goodbye" & @crlf & "Goodbye" & @crlf & "Goodbye" & @crlf & "Goodbye" & @crlf & "Goodbye" & @crlf & "Goodbye" & @crlf & "Goodbye" ;Local $sText = "Mike" ; ============= Test Fonts ================= ;Local $sFont = "Garamond" Local $sFont = "Angelyta" ;... Should Default if you do not have this Font ;Local $sFont = "Arial" ;Local $sFont = "Comic Sans Ms" ; ============================================ Local $iAttribute = 2 ;>>>> Normal = 0 -- Italic = 2 -- Underlined = 4 -- Strike = 8 Local $iWeight = 800 ;>>>> THIN = 100 -- EXTRALIGHT = 200 -- LIGHT = 300 -- NORMAL = 400 -- MEDIUM = 500 -- SEMIBOLD = 600 -- BOLD = 700 --EXTRABOLD = 800 -- HEAVY = 900 Local $hGUI = GUICreate("Auto-adjust Font Size for Varied Text Paths", 400, 100) Local $hLabel = GUICtrlCreateLabel($sText, 10, 10, 380, 80, BitOR(0x200, 0x1)) GUISetState(@SW_SHOW) _AdaptFontSize($hLabel, $iWeight, $iAttribute, $sFont) ;_AdaptFontSize($hLabel, 100, 0, "") While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func _AdaptFontSize($hCtrl, $iWeight = 100, $iAttribute = 0, $sFont = "Arial") If Not IsString($sFont) Then $sFont = "Arial" Local $iFontSize = 5, $iXLength, $iYHeight, $hdListview Local $aPos = ControlGetPos("", "", $hCtrl) $sText = ControlGetText("", "", $hCtrl) If @error Then MsgBox(48, "Sorry, Unable to Adjust Font-Size...", "Incompatible Text Characteristics.", 5) Else ;ConsoleWrite($aPos[2] & " - " & $aPos[3] & " - " & $sText & @CRLF) ; Test-Point $hdListview = GUICtrlCreateListView("", 0, 0, 0, 0) ; dummy see below... _GUICtrlListView_AddItem($hdListview, $sText) Do $iFontSize += 0.1 ; Get max fit with small font incrementals GUICtrlSetFont($hdListview, $iFontSize, $iWeight, $iAttribute, $sFont) GUICtrlSetData($hCtrl, $sText) ; include this if you wish to FLASH-EMPHASIS update? $iXLength = _GUICtrlListView_GetStringWidth($hdListview, StringReplace($sText, @CRLF, " ")) ; Return String Length in Pixels $iYHeight = _GUICtrlListView_ApproximateViewHeight($hdListview) ; has a relational factor... * 3.8 see below... ;ConsoleWrite("String Length = " & $iXLength & @CRLF & @CRLF) ; Test-Point Until $iXLength > $aPos[2] Or $iYHeight > ($aPos[3] * 3.8) ; Strangely works slightly better then... Until $iXLength < $aPos[2] etc. $iFontSize = $iFontSize - 0.1 ; Step back into "Fit" Range... See Above GUICtrlSetFont($hCtrl, $iFontSize, $iWeight, $iAttribute, $sFont) GUICtrlSetData($hCtrl, StringReplace($sText, @CRLF, " ")) ; ConsoleWrite("String Length = " & $iXLength & @CRLF & "String Height = " & $iYHeight & @CRLF & "Font Size = " & $iFontSize & @CRLF) ; Test_Point endif EndFunc ;==>_AdaptFontSize Edited January 13 by VocabMike incorrect posting of code Link to comment Share on other sites More sharing options...
Nine Posted January 13 Share Posted January 13 When you post code, please use the method described in the link. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
VocabMike Posted January 13 Author Share Posted January 13 Sorry Nine... have corrected post above. Nine 1 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