Sign in to follow this  
Followers 0
charon

Change label color issue

3 posts in this topic

Is there some way to change a GUI label background color from green to red  after returning from a function?  I tried using

GUICtrlSetData($SNR, $COLOR_RED) ; change label bkcolor doesn't work

myGUI()

Func myGUI()
    $CurrentVersion = "0.4.93"
    ;$delayset = 2000
    $hGUI = GUICreate("Tools", 590, 150)  ;width/height 110
    ;GUICtrlCreateTab(10, 10, 390, 370)
    GUICtrlCreateTab(10, 10, 580, 135)   ;GUICtrlCreateTab(10, 10, 580, 95)
    GUICtrlCreateTabItem("Main")
$MIPCopyButton = GUICtrlCreateButton("MIP", 15, 50, 30, 20)  ;left/top/width/height
$groupForm = GUICtrlCreateGroup("Levels", 15, 100, 560, 40)  ;left/top/width/height
    GUICtrlCreateLabel("DS " , 20, 115, 30, 20) ; first cell 70 width
    ;$DSInput = GUICtrlCreateInput("", 40, 115, 30, 20)
    Local $DSInput = GUICtrlCreateLabel("", 43, 115, 40, 20)
    GUICtrlSetBkColor($DSInput, $COLOR_GREEN)
    GUICtrlSetColor($DSInput, $COLOR_WHITE)

    ;$USInput = GUICtrlCreateInput("", 100, 115, 30, 20)
    GUICtrlCreateLabel("US " , 90, 115, 30, 20) ; first cell 70 width
    Local $USInput = GUICtrlCreateLabel("", 110, 115, 40, 20)
    GUICtrlSetBkColor($USInput, $COLOR_GREEN)
    GUICtrlSetColor($USInput, $COLOR_WHITE)

    ;GUICtrlSetBkColor($USInput, $COLOR_RED)

    ;$SNRInput = GUICtrlCreateInput("", 180, 115, 30, 20)
    GUICtrlCreateLabel("SNR " , 153, 115, 30, 20) ; first cell 70 width
    Local $SNRInput = GUICtrlCreateLabel("", 185, 115, 40, 20)
    Local $SNR = GUICtrlSetBkColor($SNRInput, $COLOR_GREEN)
    GUICtrlSetColor($SNRInput, $COLOR_WHITE)

    GUICtrlCreateLabel("Boot " , 230, 115, 30, 20) ; first cell 70 width
    Local $BootFile = GUICtrlCreateLabel("", 265, 115, 150, 20)
    GUICtrlSetBkColor($BootFile, $COLOR_GREEN)
    GUICtrlSetColor($BootFile, $COLOR_WHITE)
    
    GUICtrlSetState(-1, $GUI_FOCUS)
    GUISetState()
    _WinAPI_SetFocus(ControlGetHandle("Tools", "

While 1

        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                Exit
            Case $MIPCopyButton
                $MIPcopy = GUICtrlRead($data)
                ;add function here to make sure its a valid MAC
                If $MIPcopy = "" Then
                    MsgBox(0, "", "No data")
                    ;Local $MIPLength = StringLen($DataIndexLine)
                ElseIf StringLen($MIPcopy) = 12 Then
                    $myIP = GetScoutData($MIPcopy)
                    GUICtrlSetData($data, $myIP)       ;reset input box

                    ;start get levels
                    $levels = GetScoutLevels($MIPcopy)
                    _ArrayDisplay($levels)
                    GUICtrlSetData($DSInput, $levels[0])      
                    GUICtrlSetData($USInput, $levels[1])      
                    GUICtrlSetData($SNRInput, $levels[2])     
                    GUICtrlSetData($BootFile, $levels[3])     
                    GUICtrlSetData($SNR, $COLOR_RED)       ; change label bkcolor doesn't work
                    ;Local $SNR = GUICtrlSetBkColor($SNRInput, $COLOR_GREEN)
                    ;$static = GUICtrlRead($staticInput)
                    ;ClipPut($MIPcopy)
                Else
                    ClipPut($MIPcopy)
                EndIf
            Case $SIPCopyButton
            GUICtrlSetState($LMI_Radio, $GUI_UNCHECKED)
        EndSwitch
    WEnd
EndFunc

Share this post


Link to post
Share on other sites



#3 ·  Posted (edited)

Something like this? 

I'm using a button to trigger the function I wrote just for a quick example, but the important part is toggling the boolean flag variable in there from false to true, and that will call whatever you need once you have it set to true. 

**Edit I realize using a button to set a value and then using that value to call a function is redundant :) I'm assuming you will set the flag to true with something other than a button. Once the message loop sees the true "if" statement it will fire whatever you need.

#include <GuiConstantsEx.au3>

$bMyFlag = False

$hgui = GUICreate("test", 300, 300, -1, -1)
$cBtn_1 = GUICtrlCreateButton("run function", 15, 50, 130, 20)
$cLabel_1 = GUICtrlCreateLabel("DS " , 20, 115, 30, 20) ; first cell 70 width
GUICtrlSetBkColor(-1, 0x00FF00) ; -1 targets the last created control
GUISetState()

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            exit

        Case $cBtn_1
            $bMyFlag = True
    EndSwitch
    if $bMyFlag then
        testing()
        $bMyflag = False ; resetting the flag back to false
    endif
WEnd

Func testing()
    ; do whatever else happens in your function
    GUICtrlSetBkColor($cLabel_1, 0xFF0000) ; setting color to Red
EndFunc
Edited by JakeKenmode

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
Sign in to follow this  
Followers 0