o=createobject("frmColorButton") o.show() read events define class frmColorButton as form add object grd as grid ; with columncount=2 procedure init create cursor zz (nColor i) insert into zz values (0xffffff) insert into zz values (0xffff7f) insert into zz values (0xff7fff) insert into zz values (0x7fffff) insert into zz values (0x7f7fff) insert into zz values (0xff7f7f) insert into zz values (0x7fff7f) with this.grd .recordsource="zz" .columncount=2 .column1.controlsource="ncolor" with .column2 scan lcName="cmd"+transform(recno(),"9") .addobject(lcName, "cmdColor", nColor) oCmd=getpem(this.grd.column2, lcName) with oCmd .visible=.t. .caption=lcName endwith endscan .sparse=.f. .dynamiccurrentcontrol=["cmd"+TRANSFORM(RECNO(),"9")] .currentcontrol="cmd1" .removeobject("text1") endwith endwith endproc procedure destroy clear events endproc enddefine define class cmdColor as commandbutton colorsource=0 procedure init(nC) this.backcolor=nC endproc *!* procedure refresh *!* this.backcolor=zz.nColor *!* endproc enddefineThe cmdColor.Refresh is where I tried to have a single button which would change color, but that didn't work. Note here that I'm having one button for each color - which may not be too elegant if you have too many colors. However, if your colors are few, up to a few dozen (more shades would make them hard to distinguish anyway), you can have a different definition of your .currentControl - maybe something like
.dynamiccurrentcontrol=["cmd"+substr(TRANSFORM(nColor,"@0"),5)]and have your commandbuttons named in a suitable manner.