I want to find the height in pixels of the space remaining on the page after the last item was added (so I can add and resize an image to fit into the remaining space).
I'm unable to find anything in the help or forums relating to 'current y pos' etc. I'm sure this has been done before now.
Any help is greatly appreciated.
Get height of remaining space on page
-
- Site Admin
- Posts: 17559
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
Re: Get height of remaining space on page
Code: Select all
function GetFreeSpaceAtTheEndOfPage(srv: TSRichViewEdit; PageNo: Integer): Integer;
var
ItemNo, Offs, Part, PageNo1, PageNo2: Integer;
rve: TCustomRichViewEdit;
R: TRect;
begin
Result := 0;
if (PageNo < 1) or (PageNo > srv.PageCount) then
exit;
rve := srv.RichViewEdit;
// getting the last item on the page
srv.GetPageLastItemNo(PageNo, ItemNo, Offs);
// if this is a middle of a table, returing 0
if (rve.GetItem(ItemNo) is TRVTableItemInfo) and
(Offs < TRVTableItemInfo(rve.GetItem(ItemNo)).RowCount - 1) then
exit;
// finding the bottom coordinates of the last item on the page, storing in Result
Part := 0;
R := Rect(0, 0, 0, 0);
while srv.GetItemBounds100(rve.RVData, ItemNo, R, PageNo1, PageNo2, Part, False) do
begin
if PageNo2 > PageNo then
break;
Result := R.Bottom;
inc(Part);
end;
// Calculating the space till the end of page
Result := srv.GetPageHeight100Pix(PageNo) - srv.GetBottomMargin100Pix(PageNo) -
Result;
end;
Re: Get height of remaining space on page
Thanks Sergey. Learning all the time.