Jump to content

how to change the color of a rectangle


Imbuter2000
 Share

Recommended Posts

I drawed a blue rectangle with this code:

$border = GUICtrlCreateGraphic(0, 0, 500, 500)
GUICtrlSetGraphic($border, $GUI_GR_COLOR, 0x0000FF) ; blue
GUICtrlSetGraphic(-1, $GUI_GR_RECT, 5, 5, 495, 495)

I want to change the color of this rectangle whenever an event occurs, however I tried to change it with another GUICtrlSetGraphic command or a GUICtrlSetColor without success.

How am I supposed to change the color of it?

Link to comment
Share on other sites

GUICtrlSetGraphic($border, $GUI_GR_COLOR, 0x0000FF) ; blue
GUICtrlSetGraphic($border, $GUI_GR_RECT, 5, 5, 495, 495)

GUICtrlSetGraphic($border, $GUI_GR_COLOR, 0xFF0000) ; red
GUICtrlSetGraphic($border, $GUI_GR_RECT, 5, 5, 495, 495)

Link to comment
Share on other sites

Here's a small example for you, don't just copy & paste, peruse the helpfile and study it:

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

Opt("GUIOnEventMode", 1)

;START gUI
$GUI1 = GUICreate("Rectangle Example", 448, 240, 192, 124)
GUISetOnEvent($GUI_EVENT_CLOSE, "GUIClose")

$border = GUICtrlCreateGraphic(55, 16, 336, 145)
GUICtrlSetGraphic($border, $GUI_GR_COLOR, 0x00000, 0xFF0000)
GUICtrlSetGraphic($border, $GUI_GR_RECT, 0, 0, 322, 126)


$Button1 = GUICtrlCreateButton("Green", 56, 192, 89, 33)
GUICtrlSetOnEvent(-1, "TurnGreen")

$Button2 = GUICtrlCreateButton("Blue", 176, 192, 89, 33)
GUICtrlSetOnEvent(-1, "TurnBlue")

$Button3 = GUICtrlCreateButton("Purple", 288, 192, 89, 33)
GUICtrlSetOnEvent(-1, "TurnPurple")

GUISetState(@SW_SHOW)
;END GUI

While 1

WEnd

Func GUIClose()
    Exit
EndFunc   ;==>GUIClose

Func TurnGreen()
    GUICtrlSetGraphic($border, $GUI_GR_COLOR, 0x00000, 0x00FF00)
    GUICtrlSetGraphic($border, $GUI_GR_RECT, 0, 0, 322, 126)
    GUICtrlSetGraphic($border, $GUI_GR_REFRESH)
EndFunc   ;==>TurnGreen

Func TurnBlue()
    GUICtrlSetGraphic($border, $GUI_GR_COLOR, 0x00000, 0x0080FF)
    GUICtrlSetGraphic($border, $GUI_GR_RECT, 0, 0, 322, 126)
    GUICtrlSetGraphic($border, $GUI_GR_REFRESH)
EndFunc   ;==>TurnBlue

Func TurnPurple()
    GUICtrlSetGraphic($border, $GUI_GR_COLOR, 0x00000, 0x8000FF)
    GUICtrlSetGraphic($border, $GUI_GR_RECT, 0, 0, 322, 126)
    GUICtrlSetGraphic($border, $GUI_GR_REFRESH)
EndFunc   ;==>TurnPurple

Also, you should put your code in autoit tags so that it will show like above...

You should pay attention to this line of code:

GUICtrlSetGraphic($border, $GUI_GR_REFRESH)

it's very important.

Just look at us.
Everything is backwards; everything is upside down. Doctors destroy health. Lawyers destroy justice. Universities destroy knowledge. Governments destroy freedom. The major media destroy information and religions destroy spirituality. ~ Michael Ellner


The internet is our one and only hope at a truly free world, do not let them take it from us...

Link to comment
Share on other sites

Here's a small example for you, don't just copy & paste, peruse the helpfile and study it:

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

Opt("GUIOnEventMode", 1)

;START gUI
$GUI1 = GUICreate("Rectangle Example", 448, 240, 192, 124)
GUISetOnEvent($GUI_EVENT_CLOSE, "GUIClose")

$border = GUICtrlCreateGraphic(55, 16, 336, 145)
GUICtrlSetGraphic($border, $GUI_GR_COLOR, 0x00000, 0xFF0000)
GUICtrlSetGraphic($border, $GUI_GR_RECT, 0, 0, 322, 126)


$Button1 = GUICtrlCreateButton("Green", 56, 192, 89, 33)
GUICtrlSetOnEvent(-1, "TurnGreen")

$Button2 = GUICtrlCreateButton("Blue", 176, 192, 89, 33)
GUICtrlSetOnEvent(-1, "TurnBlue")

$Button3 = GUICtrlCreateButton("Purple", 288, 192, 89, 33)
GUICtrlSetOnEvent(-1, "TurnPurple")

GUISetState(@SW_SHOW)
;END GUI

While 1

WEnd

Func GUIClose()
    Exit
EndFunc   ;==>GUIClose

Func TurnGreen()
    GUICtrlSetGraphic($border, $GUI_GR_COLOR, 0x00000, 0x00FF00)
    GUICtrlSetGraphic($border, $GUI_GR_RECT, 0, 0, 322, 126)
    GUICtrlSetGraphic($border, $GUI_GR_REFRESH)
EndFunc   ;==>TurnGreen

Func TurnBlue()
    GUICtrlSetGraphic($border, $GUI_GR_COLOR, 0x00000, 0x0080FF)
    GUICtrlSetGraphic($border, $GUI_GR_RECT, 0, 0, 322, 126)
    GUICtrlSetGraphic($border, $GUI_GR_REFRESH)
EndFunc   ;==>TurnBlue

Func TurnPurple()
    GUICtrlSetGraphic($border, $GUI_GR_COLOR, 0x00000, 0x8000FF)
    GUICtrlSetGraphic($border, $GUI_GR_RECT, 0, 0, 322, 126)
    GUICtrlSetGraphic($border, $GUI_GR_REFRESH)
EndFunc   ;==>TurnPurple

Also, you should put your code in autoit tags so that it will show like above...

You should pay attention to this line of code:

GUICtrlSetGraphic($border, $GUI_GR_REFRESH)

it's very important.

 

Ahhh GUICtrlSetGraphic($border, $GUI_GR_REFRESH) was what I missed!  Thanks Wombat!!!

Link to comment
Share on other sites

you may want to set the thread as answered then

Just look at us.
Everything is backwards; everything is upside down. Doctors destroy health. Lawyers destroy justice. Universities destroy knowledge. Governments destroy freedom. The major media destroy information and religions destroy spirituality. ~ Michael Ellner


The internet is our one and only hope at a truly free world, do not let them take it from us...

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...