如何让StringGrid中相邻两行显示不同颜色呢,如1、3、5、7行...一种颜色,2、4、6、8行...另一种颜色

解决方案 »

  1.   

    procedure TForm1.sg1DrawCell(Sender: TObject; ACol,
      ARow: Integer; Rect: TRect; State: TGridDrawState);
    var
      i:integer;
    begin
      for i:=0 to sg1.ColCount do
      begin
        if ((aCOL mod 2=0)) and (arow>0) then
        begin
          SG1.Canvas.Brush.Color := clMoneyGreen;
          sg1.Canvas.Font.Color:=clred;
          SG1.canvas.FillRect (rect);
          SG1.Canvas.textout(rect.left+1,rect.Top ,SG1.cells[acol,arow]);
        end;
        if ((aCOL mod 2<>0)) and (arow>0) then
        begin
          SG1.Canvas.Brush.Color := clblue;
          sg1.Canvas.Font.Color:=clred;
          SG1.canvas.FillRect (rect);
          SG1.Canvas.textout(rect.left+1,rect.Top ,SG1.cells[acol,arow]);
        end;  end;
      

  2.   

    剛才那個貼錯了,再看正確的:
       if (arow>0) then
        if (((arow) mod 2=0)) and (acol>0) then
        begin
          SG1.Canvas.Brush.Color := clMoneyGreen;
          sg1.Canvas.Font.Color:=clred;
          SG1.canvas.FillRect (rect);
          SG1.Canvas.textout(rect.left+1,rect.Top ,SG1.cells[acol,arow]);
        end;
        if (((arow) mod 2<>0)) and (acol>0) then
        begin
          SG1.Canvas.Brush.Color := clblue;
          sg1.Canvas.Font.Color:=clred;
          SG1.canvas.FillRect (rect);
          SG1.Canvas.textout(rect.left+1,rect.Top ,SG1.cells[acol,arow]);
        end;