我的代码是:stringgrid1.Cells[i, d] := Rom+#13#10+sta;换不了 
原先0303VR 
现在要的效果:0303 
        VR 

解决方案 »

  1.   

    DrawGrid有DrawCell事件,可以自己画,
    不知道StringGrid有没类似的事件
      

  2.   

    可以在DrawCell时用DrawText重新“画”这些字符
      

  3.   

    这里以前有一个大牛名叫“老冯”(现在这位冯老师潜水N久了)他写过一个代码,楼主可以参考:
    procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
      Rect: TRect; State: TGridDrawState);
    var{这个DrawCell里的代码是老冯写的}
      HCell: Integer;
      HRow: Integer;
      SCell: string;
    begin
      with TStringGrid(Sender) do begin
        SCell := Cells[ACol, ARow];
        HRow := RowHeights[ARow];
        Canvas.FillRect(Rect);
        HCell := DrawText(Canvas.Handle, PChar(SCell), Length(SCell), Rect, DT_Center or DT_VCenter or DT_WORDBREAK );
        if HCell > HRow then RowHeights[ARow] := HCell;
      end;
    end;procedure TForm1.FormCreate(Sender: TObject);
    begin
      StringGrid1.Options := [goFixedVertLine,goFixedHorzLine,goVertLine,goHorzLine,goRangeSelect,goEditing,goAlwaysShowEditor];
    end;procedure TForm1.StringGrid1KeyPress(Sender: TObject; var Key: Char);
    begin
      with TStringGrid(Sender) do
        if Key=#13 then begin
          Cells[Col,Row] := Cells[Col,Row]+#13+#10;
          Options := [goFixedVertLine,goFixedHorzLine,goVertLine,goHorzLine,goRangeSelect,goEditing,goAlwaysShowEditor];
        end;
    end;
      

  4.   

    我之前写的是在StringGrid1DrawCell里用textout,自己计算坐标和rect进行draw.
    然后用repaint重绘.
    好像要先禁用自动重绘. 
      

  5.   


    谢谢德贤版主帮忙删掉回复。
    潜水半年,重新回来回贴,虽然回的多是一些难度不高的技术话题,但很反感这种不尊重回贴人的不负责结贴行为,因此措辞偏激了一些。事后感到言辞过于激烈,想编辑但无权限。建议CSDN出台惩罚和投诉办法(已结贴貌似不可再由版主重新评分?)
    诚然,“分不算什么”(这句老话我记忆深刻),但是要么你发零分贴,既然你发贴时投入了分数,就要公平公正地评分,这是对别人的尊重。