Resize memo to fit text
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.
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
if so set up the stretching props of bands and memos to maxheight and verical alignment to center.
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)
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;
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 !