Jump to content

changing graphic colors


argv1
 Share

Recommended Posts

Hi folks,

I would like to create a traffic light like gui object, where the user (me) can see if something went well or not.

For that I wrote this:

$Kontrolllampe1 = GUICtrlCreateGraphic(432, 20, 31, 32)
GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0x000000, 0xFFCC33) ;== yellow
GUICtrlSetGraphic(-1, $GUI_GR_ELLIPSE, 6, 8, 20, 19)

I got seven traffic lights.

When I would like to change the color, what did I need to do?

I tried this:

Case $ButtonErstellen
        $Kontrolllampe1 = GUICtrlCreateGraphic(432, 20, 31, 32)
        GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0x000000, 0x00FF00) ;== green
        GUICtrlSetGraphic(-1, $GUI_GR_ELLIPSE, 6, 8, 20, 19)

but I have to click the button twice to see a result

Is there a possibility that I use something like

Case $ButtonErstellen
        $Kontrolllampe1 = GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0x000000, 0x00FF00) ;== green

(I know this doesn't work)

Thank you in advance

Link to comment
Share on other sites

  • Moderators

argv1,

Stop posting support questions in the Examples section!

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

this works:

Opt("GuiOnEventMode", 1)

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>

$hWnd = GUICreate("", 700, 320)
$Kontrolllampe1 = GUICtrlCreateGraphic(5, 5, 30, 31)
GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0x000000, 0xFFCC33) ;== yellow
GUICtrlSetGraphic(-1, $GUI_GR_ELLIPSE, 6, 8, 20, 19)
GUICtrlSetGraphic(-1, $GUI_GR_CLOSE)
GUICtrlSetOnEvent(-1, "_Change")

GUISetState()
GUISetOnEvent(-3, "_MyExit")

While 1
    Sleep(10)
WEnd

Func _MyExit()
    Exit
EndFunc

Func _Change()
    $iColor = Execute("0x"&Hex(Random(0, 255, 1), 2)&Hex(Random(0, 255, 1), 2)&Hex(Random(0, 255, 1), 2))
    GUICtrlSetGraphic($Kontrolllampe1, $GUI_GR_COLOR, 0x000000, $iColor) ;== yellow
    GUICtrlSetGraphic($Kontrolllampe1, $GUI_GR_ELLIPSE, 6, 8, 20, 19)
    GUICtrlSetGraphic(-1, $GUI_GR_CLOSE)
    GUICtrlSetGraphic($Kontrolllampe1, $GUI_GR_REFRESH)
    ConsoleWrite("_"&@CRLF)
EndFunc

Click on the graphic to change the color

Link to comment
Share on other sites

and this...

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>

Local $gui010 = GUICreate('Stop Light')

Local $gr010 = GUICtrlCreateGraphic(50, 50, 130, 130)
GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0x00ff00, 0x00FF00)
GUICtrlSetGraphic(-1, $GUI_GR_ELLIPSE, 35, 50, 230, 230)

GUISetState()

AdlibRegister('StopAndGo', 500)

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $gui_event_close
            Exit
    EndSwitch
WEnd

Func StopAndGo()

    Local Static $sw = True

    Local $color = ($sw = True) ? 0x00ff00 : 0xff0000

    GUICtrlSetGraphic($gr010, $GUI_GR_COLOR, $color, $color)
    GUICtrlSetGraphic($gr010, $GUI_GR_ELLIPSE, 35, 50, 230, 230)
    GUICtrlSetGraphic($gr010, $Gui_gr_refresh)

    $sw = Not $sw

EndFunc   ;==>StopAndGo

 

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Link to comment
Share on other sites

and this...

Click the traffic light to change colour.
The traffic lights can be dragged.
Changing the value of  the variable, $iFactor, will change the size of the traffic lights.
Press Esc to exit.

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <SendMessage.au3>

; ============ Get focus on traffic lights then press Esc to Exit ===================
; ============ Traffic lights can be dragged                      ===================

Global $iFactor = 14 ; <<----- Bigger the number, the bigger the traffic lights size - say between 0.5 and 14+
Local $iLeft = 20, $iTop = 20
Global $aLights[3], $iFlag = 1
Global $hWnd = GUICreate("", 28 * $iFactor, 70 * $iFactor, $iLeft, $iTop, $WS_POPUP + $WS_BORDER, $WS_EX_TOPMOST)
GUISetBkColor(0x808080, $hWnd)

For $i = 0 To 2
    $aLights[$i] = GUICtrlCreateGraphic(2 * $iFactor, (2 + ($i * 20)) * $iFactor, 28 * $iFactor, 31 * $iFactor)
    GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0x000000, $i = 0 ? 0xFF0000 : 0x000000) ;== red
    GUICtrlSetGraphic(-1, $GUI_GR_ELLIPSE, 2 * $iFactor, 2 * $iFactor, 20 * $iFactor, 20 * $iFactor)
Next

GUISetState()

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $GUI_EVENT_PRIMARYDOWN
            _SendMessage($hWnd, $WM_SYSCOMMAND, 0xF012, 0)
        Case $GUI_EVENT_PRIMARYUP
            _Change()
    EndSwitch
WEnd


Func _Change()
    $iFlag = Mod($iFlag + 1, 3)

    GUICtrlSetGraphic($aLights[0], $GUI_GR_COLOR, 0x000000, $iFlag = 1 ? 0xFF0000 : 0x000000) ;== Red else Black
    GUICtrlSetGraphic($aLights[0], $GUI_GR_ELLIPSE, 2 * $iFactor, 2 * $iFactor, 20 * $iFactor, 20 * $iFactor)
    GUICtrlSetGraphic($aLights[0], $GUI_GR_REFRESH)

    GUICtrlSetGraphic($aLights[1], $GUI_GR_COLOR, 0x000000, ($iFlag = 0) ? 0xFFFF00 : 0x000000) ;== Yellow else Black
    GUICtrlSetGraphic($aLights[1], $GUI_GR_ELLIPSE, 2 * $iFactor, 2 * $iFactor, 20 * $iFactor, 20 * $iFactor)
    GUICtrlSetGraphic($aLights[1], $GUI_GR_REFRESH)

    GUICtrlSetGraphic($aLights[2], $GUI_GR_COLOR, 0x000000, $iFlag = 2 ? 0x00FF00 : 0x000000) ;== Green else Black
    GUICtrlSetGraphic($aLights[2], $GUI_GR_ELLIPSE, 2 * $iFactor, 2 * $iFactor, 20 * $iFactor, 20 * $iFactor)
    GUICtrlSetGraphic($aLights[2], $GUI_GR_REFRESH)
EndFunc   ;==>_Change

 

Link to comment
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
 Share

×
×
  • Create New...