Hier eine kleine Demo mit der UDF _StringSize.au3 von Melba23 ...funktioniert allerdings nicht perfekt, wenn die Schriftart kursiv ist, dann fehlt rechts bei einigen ein kleines Stück.
ReSizeLabel.au3
C
;-- TIME_STAMP 2018-11-25 19:12:47 v 0.1
#include <GUIConstantsEx.au3>
#include <Array.au3>
#include <Misc.au3>
;~ #include <StringSize.au3> ; wenn die Datei im User-Include-Verzeichnis ist
#include "StringSize.au3" ; wenn die Datei im Script-Verzeichnis ist
Global $g_idButton14, $g_idButton24, $g_idButton32, $g_idButton64, $g_idButton72, $g_idButtonRestore, $g_idLabelSize, $g_idLabelAttrib
Example()
Func Example()
Local $hGUI = GUICreate("StringSize-Demo", 1010, 270)
Local $sText = 'Ich bin ein Label'
Local $iSize = 8.5, $iWeight = 800, $iAttrib = 0, $sName = 'Arial', $iWidth = 990
Local $idLabel = GUICtrlCreateLabel($sText, 10, 30, 140, 22)
GUICtrlSetFont(-1, $iSize, $iWeight, $iAttrib, $sName)
$g_idButton14 = GUICtrlCreateButton("[F2] ReSize Label to 14", 10, 130, 156, 32)
GUICtrlSetBkColor(-1, 0x5F9EA0)
$g_idButton24 = GUICtrlCreateButton("[F3] ReSize Label to 24", 176, 130, 156, 32)
GUICtrlSetBkColor(-1, 0x5F9EA0)
$g_idButton32 = GUICtrlCreateButton("[F4] ReSize Label to 32", 342, 130, 156, 32)
GUICtrlSetBkColor(-1, 0x5F9EA0)
$g_idButton64 = GUICtrlCreateButton("[F5] ReSize Label to 64", 508, 130, 156, 32)
GUICtrlSetBkColor(-1, 0x5F9EA0)
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
; Ab Schriftgröße 72 scheint AutoIt bei einigen Fonts arge Probleme zu bekommen - die Buttons reagieren dann mehrere Sekunden nicht mehr!
; Mit Schriftgröße 65 fängt es an (bei Arial z.B. nicht) und ab 71 wird es dann arge, doch mit den Accelerators geht es trotzdem... hm...
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
$g_idButton72 = GUICtrlCreateButton("[F6] ReSize Label to 72", 674, 130, 156, 32)
GUICtrlSetBkColor(-1, 0xFF0000)
$g_idButtonRestore = GUICtrlCreateButton("[F1] Restore Label Size", 840, 130, 156, 32)
;~ GUICtrlSetColor(-1, 0x00FF00)
GUICtrlSetBkColor(-1, 0xB34EE9)
Local $idChooseFont = GUICtrlCreateButton("Andere Schriftart auswählen...", 10, 170, 986, 32)
GUICtrlCreateLabel('Aktuelle Schrifart', 10, 210, 220, 22)
GUICtrlSetFont(-1, 14)
$g_idLabelSize = GUICtrlCreateLabel('Size : ' & $iSize, 10, 240, 120, 22)
GUICtrlSetFont(-1, 11, 400, 0, 'Courier New')
Local $idLabelWeight = GUICtrlCreateLabel('Weight : ' & $iWeight, 140, 240, 120, 22)
GUICtrlSetFont(-1, 11, 400, 0, 'Courier New')
;~ $bItalic (2), $bUnderline (4), $bStrikethru (8)
$g_idLabelAttrib = GUICtrlCreateLabel('Attrib : ' & $iAttrib & _GetsAttribString($iAttrib), 270, 240, 420, 22)
GUICtrlSetFont(-1, 11, 400, 0, 'Courier New')
Local $idLabelName = GUICtrlCreateLabel('Name : ' & $sName, 690, 240, 220, 22)
GUICtrlSetFont(-1, 11, 400, 0, 'Courier New')
; Set GUIAccelerators for the button controlIDs
Local $aAccelKeys[6][2] = [["{F1}", $g_idButtonRestore], ["{F2}", $g_idButton14], ["{F3}", $g_idButton24], ["{F4}", $g_idButton32], ["{F5}", $g_idButton64], ["{F6}", $g_idButton72]]
GUISetAccelerators($aAccelKeys)
GUISetState(@SW_SHOW)
; Loop until the user exits.
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
ExitLoop
Case $g_idButton14
_SetLabel($idLabel, $sText, 14, $iWeight, $iAttrib, $sName, $iWidth)
Case $g_idButton24
_SetLabel($idLabel, $sText, 24, $iWeight, $iAttrib, $sName, $iWidth)
Case $g_idButton32
_SetLabel($idLabel, $sText, 32, $iWeight, $iAttrib, $sName, $iWidth)
Case $g_idButton64
_SetLabel($idLabel, $sText, 64, $iWeight, $iAttrib, $sName, $iWidth)
Case $g_idButton72
_SetLabel($idLabel, $sText, 72, $iWeight, $iAttrib, $sName, $iWidth) ; <<<<<<<< Buttons reagieren mehrere Sekunden nicht mehr!
Case $g_idButtonRestore
_SetLabel($idLabel, $sText, $iSize, $iWeight, $iAttrib, $sName, $iWidth)
Case $idChooseFont
; _ChooseFont liefert ein Array zurück, in dem alle Werte als String gespeichert sind.
; _StringSize prüft aber den Typ und will für: $iSize = Number, $iWeight & $iAttrib = Int, $sText = String
Local $a_vFont = _ChooseFont("Arial", 8)
If @error Then
MsgBox($MB_SYSTEMMODAL, "", "Error _ChooseFont: " & @error)
Else
;~ $iSize = Number($a_vFont[3]) ; dann funktioniert _SwitchButtonColor evtl. nicht mehr, weil die neue Schrifgröße nicht gefunden wird.
$iWeight = Int($a_vFont[4])
$iAttrib = Int($a_vFont[1])
ConsoleWrite("! @@ Debug line" & @TAB & @ScriptLineNumber & " var: $iAttrib --> " & $iAttrib & @CRLF)
$sName = $a_vFont[2]
GUICtrlSetData($g_idLabelSize, 'Size : ' & $iSize)
GUICtrlSetData($idLabelWeight, 'Weight : ' & $iWeight)
GUICtrlSetData($g_idLabelAttrib, 'Attrib : ' & $iAttrib & _GetsAttribString($iAttrib))
GUICtrlSetData($idLabelName, 'Name : ' & $sName)
_SetLabel($idLabel, $sText, $iSize, $iWeight, $iAttrib, $sName, $iWidth)
EndIf
EndSwitch
WEnd
EndFunc ;==>Example
Func _SetLabel($idLabel, $sText, $iSize, $iWeight, $iAttrib, $sName, $iWidth)
ConsoleWrite('Get StringSize ' & $iSize & ' ...')
Local $aStringSize = _StringSize($sText, $iSize, $iWeight, $iAttrib, $sName, $iWidth)
If @error Then
ConsoleWrite(' Error!' & @CRLF)
ConsoleWrite("@@ Debug line" & @TAB & @ScriptLineNumber & " var: $aStringSize --> " & $aStringSize & @CRLF & "!@ " & @TAB & "#Error: " & @error & @TAB & "#Extended: " & @extended & @CRLF)
ConsoleWrite("$sText --> " & $sText & @CRLF)
ConsoleWrite("$iSize --> " & $iSize & @CRLF)
ConsoleWrite("$iWeight --> " & $iWeight & @CRLF)
ConsoleWrite("$iAttrib --> " & $iAttrib & @CRLF)
ConsoleWrite("$sName --> " & $sName & @CRLF)
ConsoleWrite("$iWidth --> " & $iWidth & @CRLF)
Return False
Else
ConsoleWrite(' Ok!' & @CRLF)
_SwitchButtonColor($iSize)
ConsoleWrite('> $aStringSize = ' & _ArrayToString($aStringSize, ', ') & @CRLF)
GUICtrlSetFont($idLabel, $iSize, $iWeight, $iAttrib, $sName)
GUICtrlSetData($idLabel, $aStringSize[0])
GUICtrlSetData($g_idLabelSize, 'Size : ' & $iSize)
Local $aPos = ControlGetPos(GUICtrlGetHandle($idLabel), '', '')
ConsoleWrite('> $aPos = ' & _ArrayToString($aPos, ', ') & @CRLF)
GUICtrlSetPos($idLabel, $aPos[0], $aPos[1], $aStringSize[2], $aStringSize[3])
Return True
EndIf
EndFunc ;==>_SetLabel
Func _SwitchButtonColor($iSize)
Local Static $iLastSize, $aButtonIDs = [[14, $g_idButton14], [24, $g_idButton24], [32, $g_idButton32], [64, $g_idButton64], [72, $g_idButton72]]
Local $idButton = _ArraySearch($aButtonIDs, $iLastSize)
GUICtrlSetColor($idButton > -1 ? $aButtonIDs[$idButton][1] : $g_idButtonRestore, 0x000000)
$idButton = _ArraySearch($aButtonIDs, $iSize)
GUICtrlSetColor($idButton > -1 ? $aButtonIDs[$idButton][1] : $g_idButtonRestore, 0x00FF00)
$iLastSize = $iSize
EndFunc ;==>_SwitchButtonColor
Func _GetsAttribString($iAttrib)
Local $sAttrib
If $iAttrib = 0 Then $sAttrib = ''
If BitAND($iAttrib, 2) Then $sAttrib = 'Italic'
If BitAND($iAttrib, 4) Then $sAttrib &= ', Underline'
If BitAND($iAttrib, 8) Then $sAttrib &= ', Strikethru'
If StringLeft($sAttrib, 2) = ', ' Then $sAttrib = StringTrimLeft($sAttrib, 2)
If $sAttrib Then $sAttrib = ' (' & $sAttrib & ')'
Return $sAttrib
EndFunc ;==>_GetsAttribString
Alles anzeigen
Ab Schriftgröße 72 scheint AutoIt bei einigen Fonts arge Probleme zu bekommen - die Buttons reagieren dann mehrere Sekunden nicht mehr!
Mit Schriftgröße 65 fängt es an (bei Arial z.B. nicht) und ab 71 wird es dann arge, doch mit den Accelerators geht es trotzdem... hm...