0

我从德尔福开始。我对 TStringGrid 和 Colored the Cell 有疑问。我在选择时使用此代码为背景着色:

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 为什么。

  1. 当我选择 3 个红色的单元格时。(工作正常) 在此处输入图像描述

  2. 改变另一个单元格的颜色,改变第一个单元格TT 在此处输入图像描述

    http://i.stack.imgur.com/umG0r.png http://i.stack.imgur.com/1o93C.png

帮助!!!

4

2 回答 2

2

如果您只想为选定的单元格着色,则必须检查传入的 State 参数,并且仅在选中 State 时才绘制。

此外,您正在该例程中绘制 3 倍单元格。只要把 MatrizGeneral.Canvas.FillRect(Rect); 最后一次,每个 IF 块都不需要它。

于 2014-03-18T03:58:43.807 回答
0

我使用这个规则为使用无线电组选择的单元格着色:

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;

结尾;

效果很好!

于 2014-03-19T14:13:57.027 回答