stringgrid在颜色变换前是有内容的,在变换颜色以后,原来的内容消失了,请问各位大虾如何解决这类问题?

解决方案 »

  1.   

    代码太多了,不好贴
    我再详细的解释一下,我的意思是:在stringgrid开始的时候,所有的行和列都没有颜色,但上面有字
    当我按按钮的时候,只要符合某一条件的所有的列的底色都变成红色,但同时要保留以前上面的
    信息
      

  2.   

    procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
      Rect: TRect; State: TGridDrawState);
    begin
      StringGrid1.Canvas.Brush.Color:= clInactiveCaptionText;
      StringGrid1.Canvas.FillRect(Rect);
      StringGrid1.Canvas.TextOut(Rect.Left+3,Rect.Top+3,StringGrid1.Cells[aCol,aRow]);
    end;
      

  3.   

    在ondrawcell中加上这么几句
       strValue  :=  StringGrid.Cells[ACol,ARow];
       Canvas.Font  :=  Font;
       //在矩形框中写值
       Canvas.TextRect(Rect,Rect.Left+5,Rect.Top+(Rect.Bottom-Rect.Top-Canvas.TextHeight(  strValue)) div 2,strValue);