在Cell中自绘,事件是OnDrawColumnCell

解决方案 »

  1.   

    看你的另一贴:
    http://topic.csdn.net/u/20100323/20/8f742eb6-2ca4-4a0e-9612-9f10d385c4e1.html
      

  2.   


    在OnDrawCell事件中写下面 
    with stringgrid1 of
        Canvas.Font.Size:= CellFontBrush[ACol].Size; //字体大小
        Canvas.Font.Color:= CellFontBrush[ACol].Color; //字体颜色
        Canvas.Brush.color:=CellColorBrush[ACol];//颜色背景
        Canvas.FillRect(ARect);
        DrawText(self.Canvas.Handle,PChar(self.Cells[ACol,ARow]),Length(self.Cells[ACol,ARow]),ARect,1 or DT_SINGLELINE or 4); //文字居中
    end;  // }
      

  3.   

    在OnDrawCell事件中写下面 
    with stringgrid1 of
        Canvas.Font.Size:= CellFontBrush[ACol].Size; //字体大小
        Canvas.Font.Color:= CellFontBrush[ACol].Color; //字体颜色
        Canvas.Brush.color:=CellColorBrush[ACol];//颜色背景
        Canvas.FillRect(ARect);
        DrawText(Canvas.Handle,PChar(Cells[ACol,ARow]),Length(Cells[ACol,ARow]),ARect,1 or DT_SINGLELINE or 4); //文字居中
    end;
      

  4.   


    procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
      Rect: TRect; State: TGridDrawState);
    begin
      if ACol = 1 then
      begin
        StringGrid1.Canvas.Font.Color := clRed;
        StringGrid1.Canvas.TextOut(Rect.Left,Rect.Top,'A');
        StringGrid1.Canvas.Font.Color := clBlue;
        StringGrid1.Canvas.TextOut(Rect.Left+10,Rect.Top,'B');
        StringGrid1.Canvas.Font.Color := clGreen;
        StringGrid1.Canvas.TextOut(Rect.Left+20,Rect.Top,'C');
      end;
    end;