Resize memo to fit text

hsmhsm
edited 7:35AM in FastReport 4.0
I have a simple master data band with about 20 single line memos with borders.
The memos are arranged so they touch each other and have the same height as the data band.
This gives the appearance of a grid with 'rows' and 'columns' when the data is displayed.

Using autofit = true I can resize an individual memo to fit the text it contains in that record but that gives a ragged 'column' edge as any given field could vary in size from record to record.

Is there any code snippet available that will help me resize every memo to fit the biggest text that field contains and also then shift each of the other memos rightwards so that the final display retains its grid like appearance with each 'column' having straight sides?

(The page width might also need increasing to fit all the memos in)

The effect I'm after is a bit like when a spreadsheet auto fits its columns.

Comments

  • gordkgordk St.Catherines On. Canada.
    edited 7:35AM
    Can you work with word wrapping in the memos
    if so set up the stretching props of bands and memos to maxheight and verical alignment to center.
  • hsmhsm
    edited 7:35AM
    gordk wrote: »
    Can you work with word wrapping in the memos
    if so set up the stretching props of bands and memos to maxheight and verical alignment to center.
    I thought of doing that but I'd prefer not to if possible.
    The report duplicates some data that is being sent via email as a csv file and is used to show the user what has been sent.
    So I'd prefer it to look the same as a csv file. ie each record on a single line, like a spreadsheet.

    I thought of setting all the memos to autowidth and then somehow using the obp to find out how wide memo1 is, make memo2.left the same as memo2.width, then make memo3.left the same as memo1.withd+memo2.width and so on.
    But I'm not sure how to do this efficiently in code or where to do it (obp, oad etc)
  • gordkgordk St.Catherines On. Canada.
    edited 7:35AM
    here is a sample ive only shown the first 2 memos in the band but youll get the idea i'm sure
    make sure the memos are created in order left to right within the band;
    var
    oldleft:double;
    procedure Memo8OnAfterData(Sender: TfrxComponent);
    begin
    if memo8.calcwidth >memo8.width then
    begin
    oldleft := memo9.left; //get design left of next memo
    //repositionthenext memo
    memo9.left :=memo8.left +memo8.calcwidth+5;
    end;
    end;

    procedure Memo9OnAfterPrint(Sender: TfrxComponent);
    begin
    memo9.left := oldleft; // reset to design left
    end;
  • hsmhsm
    edited 7:35AM
    Thank you very much

    I wasn't sure which event to use as it had to be one that occured after the autosize event happened.

    Your code will do nicely !

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.