[英]How colored the Cell of StringGrid Delphi XE2?
我从Delphi开始。 我遇到了TStringGrid和Colored the Cell的问题。 我选择BackGround时使用此代码进行颜色处理:
procedure TForm_Matrix.MatrizGeneralDrawCell(Sender: TObject;
ACol, ARow: Integer; Rect: TRect; State: TGridDrawState);
begin
ACol:=MatrizGeneral.Col;
ARow:=MatrizGeneral.Row;
begin
if (RBAlto.Checked = True) then // Nivel de color ROJO - ALTO
MatrizGeneral.Canvas.Brush.Color :=clRed;
MatrizGeneral.Canvas.FillRect(Rect);
if (RBMedio.Checked = True) then
MatrizGeneral.Canvas.Brush.Color :=clYellow;
MatrizGeneral.Canvas.FillRect(Rect);
if (RBBajo.Checked = True) then
MatrizGeneral.Canvas.Brush.Color :=clLime;
MatrizGeneral.Canvas.FillRect(Rect);
end;
end;
它的工作,但当我尝试改变颜色改变选择的细胞,和第一个细胞idk为什么。
当我选择3个红色的单元格时。 (工作正常)
改变另一个细胞的颜色,改变第一个细胞TT
http://i.stack.imgur.com/umG0r.png http://i.stack.imgur.com/1o93C.png
救命!!!
如果要仅为选定的单元格着色,则必须检查传入的State参数,并且仅在选择State时绘制。
此外,您正在该例程中绘制单元格3x。 只需输入MatrizGeneral.Canvas.FillRect(Rect); 一旦结束,每个IF块都不需要它。
我使用这个rutine为用放射性组选择的细胞着色:
if MatrizGeneral.Cells[ACol,ARow] <> '' then begin
case StrToInt(MatrizGeneral.Cells[ACol,ARow]) of
0: BGColor := clRed;
1: BGColor := clYellow;
2: BGColor := clLime;
else
BGColor := clWhite;
end;
with MatrizGeneral do begin
Canvas.Brush.Color := BGColor;
Canvas.FillRect(Rect);
if (gdFocused in State) then
Canvas.Font.Color := clWhite
else
Canvas.Font.Color := clBlack;
end;
结束;
效果很好!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.