Jump to content

Recommended Posts

Posted (edited)

Hi

I'm trying to make a status dot that when something is happening the dot is red and when it's idle it is green

however I'm not having much luck, the script below you can see the label change but not the dot.

can someone show me whats wrong

thanks

#include <GUIConstants.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("AForm1", 349, 152, 193, 115)
$Graphic1 = GUICtrlCreateGraphic(8, 8, 49, 49)
GUICtrlSetGraphic(-1,$GUI_GR_COLOR, 0x00ff00,0x00ff00)
GUICtrlSetGraphic(-1,$GUI_GR_ELLIPSE, 5,5, 10,10)
$label = GuiCtrlCreateLabel("Green",20,60,200,20)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

For $i = 1 to 5
    Sleep (2000)
    Switch $i
        Case 1,3,5
            GUICtrlSetGraphic($Graphic1,$GUI_GR_COLOR, 0xff0000,0xff0000)
            GUICtrlSetData($label,"Red")
        Case Else
            GUICtrlSetGraphic($Graphic1,$GUI_GR_COLOR, 0x00ff00,0x00ff00)
            GUICtrlSetData($label,"Green")
    Endswitch
    
Next
Sleep (2000)
Edited by ChrisL
Posted

Try explicit control name instead of -1 in GUICtrlSetGraphic()

#include <GUIConstants.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("AForm1", 349, 152, 193, 115)
$Graphic1 = GUICtrlCreateGraphic(8, 8, 49, 49)
GUICtrlSetGraphic(-1,$GUI_GR_COLOR, 0x00ff00,0x00ff00)
GUICtrlSetGraphic(-1,$GUI_GR_ELLIPSE, 5,5, 10,10)
$label = GuiCtrlCreateLabel("Green",20,60,200,20)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

For $i = 1 to 5
    Sleep (2000)
    Switch $i
        Case 1,3,5
            GUICtrlSetGraphic($Graphic1,$GUI_GR_COLOR, 0xff0000,0xff0000)
            GUICtrlSetData($label,"Red")
        Case Else
            GUICtrlSetGraphic($Graphic1,$GUI_GR_COLOR, 0x00ff00,0x00ff00)
            GUICtrlSetData($label,"Green")
    Endswitch
    
Next
Sleep (2000)
Posted

Try explicit control name instead of -1 in GUICtrlSetGraphic()

#include <GUIConstants.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("AForm1", 349, 152, 193, 115)
$Graphic1 = GUICtrlCreateGraphic(8, 8, 49, 49)
GUICtrlSetGraphic(-1,$GUI_GR_COLOR, 0x00ff00,0x00ff00)
GUICtrlSetGraphic(-1,$GUI_GR_ELLIPSE, 5,5, 10,10)
$label = GuiCtrlCreateLabel("Green",20,60,200,20)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

For $i = 1 to 5
    Sleep (2000)
    Switch $i
        Case 1,3,5
            GUICtrlSetGraphic($Graphic1,$GUI_GR_COLOR, 0xff0000,0xff0000)
            GUICtrlSetData($label,"Red")
        Case Else
            GUICtrlSetGraphic($Graphic1,$GUI_GR_COLOR, 0x00ff00,0x00ff00)
            GUICtrlSetData($label,"Green")
    Endswitch
    
Next
Sleep (2000)
Sorry I edited the first post because I later added the label to show so -1 was wrong, I edited my first post a few minutes ago. but it doesn't work like that either!
Posted

This is the only way I can get it to work, it seems a bit extreem to delete the graphic and recreate it though

Is there a better way?

#include <GUIConstants.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("AForm1", 349, 152, 193, 115)
$Graphic1 = GUICtrlCreateGraphic(8, 8, 49, 49)
GUICtrlSetGraphic(-1,$GUI_GR_COLOR, 0x00ff00,0x00ff00)
GUICtrlSetGraphic(-1,$GUI_GR_ELLIPSE, 5,5, 10,10)
$label = GuiCtrlCreateLabel("Green",20,60,200,20)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

For $i = 1 to 5
    Sleep (2000)
    Switch $i
        Case 1,3,5
            $Graphic1 = GUICtrlCreateGraphic(8, 8, 49, 49)
            GUICtrlSetGraphic($Graphic1,$GUI_GR_COLOR, 0xff0000,0xff0000)
            GUICtrlSetGraphic(-1,$GUI_GR_ELLIPSE, 5,5, 10,10)
            
            GUICtrlSetState(-1,$Gui_Show)
            GUICtrlSetData($label,"Red")
        Case Else
            $Graphic1 = GUICtrlCreateGraphic(8, 8, 49, 49)
            GUICtrlSetGraphic(-1,$GUI_GR_COLOR, 0x00ff00,0x00ff00)
            GUICtrlSetGraphic(-1,$GUI_GR_ELLIPSE, 5,5, 10,10)
            
            GUICtrlSetState(-1,$Gui_Show)
            GUICtrlSetData($label,"Green")
            
            
    Endswitch
    
Next
Sleep (2000)
Posted

Answer is GUICtrlSetGraphic($Graphic1,$GUI_GR_REFRESH)

#include <GUIConstants.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("AForm1", 349, 152, 193, 115)
$Graphic1 = GUICtrlCreateGraphic(8, 8, 49, 49)
GUICtrlSetGraphic($Graphic1,$GUI_GR_COLOR, 0x00ff00,0x00ff00)
GUICtrlSetGraphic($Graphic1,$GUI_GR_ELLIPSE, 5,5, 10,10)
$label = GuiCtrlCreateLabel("Green",20,60,200,20)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

For $i = 1 to 5
    Sleep (2000)
    Switch $i
        Case 1,3,5
            GUICtrlSetGraphic($Graphic1,$GUI_GR_COLOR, 0xff0000,0xff0000)
            GUICtrlSetGraphic($Graphic1,$GUI_GR_ELLIPSE, 5,5, 10,10)
            GUICtrlSetGraphic($Graphic1,$GUI_GR_REFRESH)
            GUICtrlSetData($label,"Red")
        Case Else
            GUICtrlSetGraphic($Graphic1,$GUI_GR_COLOR, 0x00ff00,0x00ff00)
            GUICtrlSetGraphic($Graphic1,$GUI_GR_ELLIPSE, 5,5, 10,10)
            GUICtrlSetGraphic($Graphic1,$GUI_GR_REFRESH)
            GUICtrlSetData($label,"Green")
    Endswitch
    
Next
Sleep (2000)
Posted

Thank you again for your reply, I do have an however.....

That is drawing the graphic over and over the top rather than changing the colour of the original graphic.

The graphic is very small so the affect is not too bad but it does cause a memory leak over several thousand changes, where as the crude way of deleting the graphic control and recreating it rather than drawing on top doesn't cause a leak.

Anyone know is there a way to change the colour of the original graphic without either drawing on top or re-creating the whole contro?

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
×
×
  • Create New...