delphi : how can I change color of a cell in string grid -
delphi : how can I change color of a cell in string grid -
i want alter background color ( not font ) of cell in string grid in delphi .
just 1 cell not row or column.
can i?
rruz : procedure right , works in procedure doesn't work.
my procedure:
x global array of integer
procedure tf_avalie_salon.stringgrid1drawcell(sender: tobject; acol, arow: integer; rect: trect; state: tgriddrawstate); var s: string; begin s := stringgrid1.cells[acol, arow]; stringgrid1.canvas.fillrect(rect); settextalign(stringgrid1.canvas.handle, ta_center); stringgrid1.canvas.textrect(rect,rect.left + (rect.right - rect.left) div 2, rect.top + 2, s); if (arow<>0 )and(acol<>0)and(gridclick=true) begin seek gridclick:=false; x[acol+((strtoint(edit_hafte.text)-1)*7),arow]:=strtoint(stringgrid1.cells[acol, arow]); except x[acol+((strtoint(edit_hafte.text)-1)*7),arow]:=0; stringgrid1.cells[acol,arow]:='0'; tstringgrid(sender) begin canvas.brush.color := clgreen; canvas.fillrect(rect); canvas.textout(rect.left+2,rect.top+2,cells[acol, arow]); end; end; end; end; when utilize canvas.brush.color below code , canvas.brush.color doesn't work. if inactive below code can alter cells color. need both.
s := stringgrid1.cells[acol, arow]; stringgrid1.canvas.fillrect(rect); settextalign(stringgrid1.canvas.handle, ta_center); stringgrid1.canvas.textrect(rect,rect.left + (rect.right - rect.left) div 2, rect.top + 2, s);
the rafael link contains need, using ondrawcell event way paint cells of strigngrid. check sample paint background of specific cell.
procedure tform1.stringgrid1drawcell(sender: tobject; acol, arow: integer; rect: trect; state: tgriddrawstate); begin if (acol = 3) , (arow = 2) tstringgrid(sender) begin //paint background greenish canvas.brush.color := clgreen; canvas.fillrect(rect); canvas.textout(rect.left+2,rect.top+2,cells[acol, arow]); end; end; delphi background-color tstringgrid
Comments
Post a Comment