我想在string的灰色单元中写的字能够分成两行,该怎么办呢
这样的代码行吗?
for i := 1 to SGPreRoom.ColCount - 1 do
    begin
      dt := now()+i-1;
      sdt := copy(datetostr(dt),6,2) + #13 + '-' + #13 + copy(datetostr我(dt),9,2);
      SGPreRoom.Cells[i,0] := sdt;
end

解决方案 »

  1.   

    for i := 1 to SGPreRoom.ColCount - 1 do
        begin
          dt := now()+i-1;
          sdt := copy(datetostr(dt),6,2) + #13 + '-' + #13 + copy(datetostr(dt),9,2);
          SGPreRoom.Cells[i,0] := sdt;
    end
      

  2.   

    //參考如下代碼~~
    procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
      Rect: TRect; State: TGridDrawState);
    var
      vText: PChar;
    begin
      if ARow <> 0 then Exit;
      with TStringGrid(Sender) do begin
        vText := PChar(StringReplace(Cells[ACol, ARow], '-', #13#10'-'#13#10, []));
        Canvas.FillRect(Rect);
        DrawText(Canvas.Handle, vText, StrLen(vText), Rect,
          DT_CENTER or DT_VCENTER);
        if gdFocused in State then begin
          Rect.Left := Rect.Left + 1;
          Rect.Top := Rect.Top + 1;
          Rect.Right := Rect.Right - 1;
          Rect.Bottom := Rect.Bottom - 1;
          Canvas.DrawFocusRect(Rect);
        end;
      end;
    end;procedure TForm1.FormCreate(Sender: TObject);
    var
      I: Integer;
    begin
      StringGrid1.RowHeights[0] := 50;
      for I := 1 to StringGrid1.ColCount - 1 do
        StringGrid1.Cells[I, 0] := FormatDateTime('mm"-"dd', Date + I - 1);
    end;