musvelox Posted December 17, 2020 Share Posted December 17, 2020 Hello, Hello, I am having a little problem changing the font and colour of a label that I have previously declared with the assign function, this is done in a for loop. Unfortunately I can't edit the font and colour with the attribute -1 afterwards and haven't found another way yet. Assign("LabelTestTyp" & $createVar,GUICtrlCreateLabel($createTyp, 15, 110 + $i * 25, 75, 20)) GUICtrlSetFont(-1, 11, 400, 0, "Arial") GUICtrlSetColor(-1, 0xFFFFFF) $createVar is the variable that increases by 1 after each run. Link to comment Share on other sites More sharing options...
KaFu Posted December 17, 2020 Share Posted December 17, 2020 Use Eval to obtain the control ID. #include <GUIConstantsEx.au3> Local $createVar = "Var" Local $createTyp = "Test" Local $i = 0 Local $hGUI = GUICreate("Example") Assign("LabelTestTyp" & $createVar, GUICtrlCreateLabel($createTyp, 15, 110 + $i * 25, 75, 20)) GUICtrlSetFont(Eval("LabelTestTyp" & $createVar), 11, 400, 0, "Arial") GUICtrlSetColor(Eval("LabelTestTyp" & $createVar), 0xFFFFFF) GUISetState(@SW_SHOW, $hGUI) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd GUIDelete($hGUI) OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted December 17, 2020 Share Posted December 17, 2020 @KaFu You don't need to use Eval at all: expandcollapse popup#include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> Opt("GUIOnEventMode", 1) #Region ### START Koda GUI section ### Form= Global $frmLabels = GUICreate("Labels", 405, 293, 302, 218) GUISetOnEvent($GUI_EVENT_CLOSE, "ExitApplication") GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### _CreateLabels() _GetLabelTexts() Func ExitApplication() GUIDelete($frmLabels) Exit EndFunc Func _CreateLabels() For $i = 1 To 10 Step 1 Assign("lblLabel" & $i, GUICtrlCreateLabel("Some text " & $i, 8, 8 + ($i * 20), 100, 20), $ASSIGN_FORCEGLOBAL) GUICtrlSetFont(-1, 10, 800, 0, "Arial") GUICtrlSetColor(-1, (Mod($i, 2) = 0 ? 0x00FF00 : 0xFF0000)) Next EndFunc Func _GetLabelTexts() Local $strLabel For $i = 1 To 10 Step 1 $strLabel = Eval("lblLabel" & $i) ConsoleWrite($strLabel & " " & GUICtrlRead($strLabel) & @CRLF) Next EndFunc While 1 Sleep(100) WEnd KaFu and Aelc 2 Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
musvelox Posted December 17, 2020 Author Share Posted December 17, 2020 Thank you very much, now it works 😁 Link to comment Share on other sites More sharing options...
KaFu Posted December 17, 2020 Share Posted December 17, 2020 2 hours ago, FrancescoDiMuro said: @KaFu You don't need to use Eval at all: You're right if you use it directly after creation, but with eval you can change it back and forth later on :). FrancescoDiMuro 1 OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) 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