我想让stringgrid指定列显示指定颜色,我写了如下程序段
procedure Tfrm_luru.StringGrid1DrawCell(Sender: TObject; ACol,
  ARow: Integer; Rect: TRect; State: TGridDrawState);
begin
  inherited;
 if not((acol=1) and (arow>=cp.fixedrows)) then exit;
  with stringgrid1 do
      begin
   stringgrid1.Canvas.Brush.color:=clRed;
   stringgrid1.canvas.FillRect(Rect);
  stringgrid1.canvas.TextOut(rect.left+2,rect.top+2,stringgrid1.cells[acol,arow]);      end;
end;
可系统老是提示我有非法字符,
[Error] luru.pas(667): Illegal character in input file: ' ' ($A1A1)
什么原因?

解决方案 »

  1.   

    引用别人的:怎么改变StringGrid控件某一列的背景和某一列的只读属性,StringGrid控件标题栏的对齐.怎么改变StringGrid控件某一列的背景和某一列的只读属性,StringGrid控件标题栏的对齐.请参考以下代码:
    在OnDrawCell事件中处理背景色。程序如下:
    //将第二列背景变为红色。
    procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
    Rect: TRect; State: TGridDrawState);
    begin
    if not((acol=1) and (arow>=stringgrid1.fixedrows)) then exit;
    with stringgrid1 do
    begin
      canvas.Brush.color:=clRed;
      canvas.FillRect(Rect);
      canvas.TextOut(rect.left+2,rect.top+2,cells[acol,arow])
    end;
    end;