Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change background color of a button or rectangle using Clarion 4 1

Status
Not open for further replies.

rgreenlaw

Programmer
Oct 8, 2011
1
US
Hi, I am using Clarion 4 and hope someone can help me!

I'm trying to draw rectangles or buttons on the screen, and then randomly change the background or fill color. I have tried to do this, but can't get the colors to change on a hand-coded project.

My code:

Program
! global declarations
include('equates.clw')
map !begin defining prototypes
main procedure
end !prototypes

code !begins here
main !is called
return !to OS
main procedure !defined
! local definitions
WinOne WINDOW,AT(0,0,400,400),auto

b1 Box,use(?b1),AT(100,100,20,20)
b2 box,use(?b2),AT(140,140,20,20)
b3 box,use(?b3),AT(180,180,20,20)
button,at(190,190,20,20)
END
c long(0)
code !for main procedure goes here

open(winone)

accept
case event()
of event:selected
message(c)
c=random(0,00ffffffh)
message(c)
?b1{prop:fill} = c
c=random(0,00ffffffh)
message(c)
?b2{prop:fill} = c
c=random(0,00ffffffh)
message(c)
?b3{prop:fill} = c
display
.
.

return !main procedure ends



Can anyone help?

 
Hi!

Are your message being displayed? Once or repeatedly? A better way to test would be to change colors based on a button press i.e.

Code:
WinOne    WINDOW,AT(0,0,400,400),auto
                      Box,use(?b1),AT(100,100,20,20)
                      box,use(?b2),AT(140,140,20,20)
                      box,use(?b3),AT(180,180,20,20)
                      button,at(190,190,20,20),use(?Button1)
                END
c long(0)

 code !for main procedure goes here

 open(winone)
 
 ACCEPT
  CASE EVENT()
  OF EVENT:Accepted
    CASE ACCEPTED()
    OF ?Button1
      message(c)
      c = random(0,00ffffffh)
      message(c)
      ?b1{prop:fill} = c
      c = random(0,00ffffffh)
      message(c)
      ?b2{prop:fill} = c
      c = random(0,00ffffffh)
      message(c)
      ?b3{prop:fill} = c
      display()
    END
  END
 END

Now every time you press the button the colors should change.

Regards

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top