我在StringGridOnDrawCell事件的相应调度方法DrawCell进行覆盖,希望StringGrid在处理OnDrawCell事件前先进行一些操作,代码如下:
//声明部分:
procedure DrawCell(ACol, ARow: Longint; ARect: TRect; AState: TGridDrawState);Override;
//实现部分:
procedure TStringGridEx.DrawCell(ACol, ARow: Longint; ARect: TRect; AState: TGridDrawState);
var j: Integer;
begin
   For j:= 1 To StringGrid1.ColCount-1 Do     //j是列的索引
   Begin
      With StringGrid1.Canvas Do //想要在此让某一行颜色为兰。
      Begin
         Brush.Color:=  clBlue;
         Font.Color:= clBlack;
         TextRect(ARect,ARect.Left,ARect.Top,StringGrid1.Cells[j,1]);
      End;
   End;
End;
   inherited; 
end;
//但结果是,整个StringGrid都变兰色了????请问哪里出错了??

解决方案 »

  1.   

    看看Delphi中StringGrid.DrawCell提供的示例你就明白了
      

  2.   

    For j:= 1 To StringGrid1.ColCount-1 Do     //j是列的索引
       Begin
          With StringGrid1.Canvas Do //想要在此让某一行颜色为兰。
          Begin
             Brush.Color:=  clBlue;//改变的brush的颜色而没有改回。
             Font.Color:= clBlack;
             TextRect(ARect,ARect.Left,ARect.Top,StringGrid1.Cells[j,1]);
             Brush.Color:= clWhite;改回白色。
          End;
       End;
      

  3.   

    To: d983074你的代码不对,。
    我只是想让第一行显示兰色。
      

  4.   

    //是不是把它的脑袋变蓝啊
    procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
      Rect: TRect; State: TGridDrawState);var j: Integer;
    arect:trect;
    begin
       For j:= 1 To StringGrid1.ColCount-1 Do     //j是列的索引
       Begin
         stringgrid1.FixedColor:=clblue;
          stringgrid1.FixedCols:=0;
          stringgrid1.FixedRows:=1;   End;
    End;
      

  5.   

    For j:= 1 To StringGrid1.ColCount-1 Do     
       Begin
          With StringGrid1.Canvas Do   
          Begin
             Brush.Color:=  clBlue;   //这句有问题,把整个StringGrid1都变为蓝色了
             Font.Color:= clBlack;
             TextRect(ARect,ARect.Left,ARect.Top,StringGrid1.Cells[j,1]);
          End;
       End;