Jump to content
musvelox

Changing Font and Color of a Assinged Label

Recommended Posts

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.

Share this post


Link to post
Share on other sites

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)

 

Share this post


Link to post
Share on other sites

@KaFu
You don't need to use Eval at all:

#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

:)


Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Share this post


Link to post
Share on other sites
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 :).

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...