★有没有办法不用OnDrawCell来设置StringGrid中某个单元格的背景颜色,和文字颜色???Canvas.Brush.Color:=clYellow;
Canvas.FillRect(cellRect(5,2));
使用这个后,反而把单元格的文字给插掉了

解决方案 »

  1.   

    type
      TStringGridEx = class(TStringGrid);procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
      Rect: TRect; State: TGridDrawState);
    begin
      if (ACol <> 1) or (ARow <> 1) then Exit;
      TStringGridEx(Sender).OnDrawCell := nil;
      try
        TStringGridEx(Sender).Canvas.Brush.Color := clYellow;
        TStringGridEx(Sender).Canvas.Font.Color := clRed;
        TStringGridEx(Sender).DrawCell(ACol, ARow, Rect, State);
      finally
        TStringGridEx(Sender).OnDrawCell := StringGrid1DrawCell;
      end;
    end;