How to change global font color (by pressing a button)?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
ahywhygod
Posts: 1
Joined: 06 Feb 2020, 14:13

How to change global font color (by pressing a button)?

06 Feb 2020, 14:28

Following code is part of a script. I know about GuiControl and that you can change font color of certain elements, but I want to be able to change it on button click along with background like I am doing it with the first line (if possible).

Code: Select all

Gui, Font, s13 c73B9B8
Gui, Color, 17212B
Gui, Add, Text, x+12 ym+42 w145 Right, Background Color:
Gui, Add, Text, xp yp+31 w145 Right, Font Color:
Gui, Add, Edit, x+10 ym+40 w90 cBlack vBgColor, %BgColor%
Gui, Add, Edit, xp yp+30 w90 cBlack vFColor
Gui, Add, Button, xp+100 ym+41 h26 w80 Default gBtnUpdateColor, Update

Gui, Show, AutoSize Center, Settings
Return

BtnUpdateColor:
Gui, Submit, NoHide
Gui, Color, %BgColor%
Return

GuiClose:
ExitApp
wbm1113
Posts: 18
Joined: 28 Aug 2018, 11:19

Re: How to change global font color (by pressing a button)?

07 Feb 2020, 21:32

I'd do it like this. You'll need to #Include the Class_CtlColors library into your script: https://github.com/AHK-just-me/Class_CtlColors/blob/master/Sources/Class_CtlColors.ahk

Code: Select all

global CtrlHwnds := []

Gui, Font, s13 c73B9B8
Gui, Color, 17212B

GuiAdd("Text", "MyCtrl1", "x+12 ym+42 w145 Right", "Background Color:")
GuiAdd("Text", "MyCtrl2", "xp yp+31 w145 Right", "Font Color:")
GuiAdd("Edit", "MyCtrl3", "x+10 ym+40 w90 cBlack")
GuiAdd("Edit", "MyCtrl4", "xp yp+30 w90 cBlack")

Gui, Add, Button, xp+100 ym+41 h26 w80 Default gBtnUpdateColor, Update

Gui, Show, AutoSize Center, Settings
Return

#Include %A_ScriptDir%\Class_CtlColors.ahk

GuiAdd(CtrlType, Label, Options:="", Text:="") {
    Hwnd := Label "Hwnd"
    Gui, Add, % CtrlType, % Options " Hwnd" Hwnd, % Text
    CtrlHwnds.Push(%Hwnd%)
}

CtrlGetText(CtrlHwnd) { 
    ControlGetText, RetVal,, ahk_id %CtrlHwnd%
    return RetVal
}

BtnUpdateColor:
    BGColor := CtrlGetText(CtrlHwnds[3])
    FColor := CtrlGetText(CtrlHwnds[4])

    for Index, CtrlHwnd in CtrlHwnds
        CtlColors.Change(CtrlHwnd, BGColor, FColor)
return

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot], oktavimark and 363 guests