Page 1 of 1

Moving SclRvRuler1.BottomMargin by code

Posted: Wed Sep 13, 2023 6:18 pm
by fara2000
Hello Sergey, Hello active customers,
I must be able to move the SclRvRuler1 from point A to point B by code!. The document contains a single Page.
The point B should be at the Bottom of the last item in the SRichViewEdit1 page, in this case a table1.

By the following line :
SclRvRuler1.BottomMargin:=SclRvRuler1.BottomMargin+1;
I could move the bottom of the SclRvRuler1 upword by one point!

Please I need to know how to choose the correct "step" (distance in points between A an B) so I can accomplish that in one step?
SclRvRuler1.BottomMargin:=SclRvRuler1.BottomMargin+Step;
It is a task I requested in previous post without having a satisfying answer.

I believe in your Abilty Sergey, Please would you try to figure out a solution for this issue?! Step:=????????
Thank you in advance!!
Screenshot 2023-09-13 173851.jpg
Screenshot 2023-09-13 173851.jpg (59.24 KiB) Viewed 28591 times

Re: Moving SclRvRuler1.BottomMargin by code

Posted: Thu Sep 14, 2023 9:13 am
by Sergey Tkachenko
If you want to change the bottom page margin in code, just change it in code. A ruler is not needed for this operation. If TSRichViewEdit has a linked ruler, the ruler will be updated according to the change.
You can simply assign SRichViewEdit.BottomMargin, but this assignment is not an editing operation (not undoable by the user).
Use

Code: Select all

SRichViewEdit.SetFloatPropertyEd(srvfpPPBottomMargin, NewMarginValue, True);
NewMarginValue is measured in SRichViewEdit.UnitsProgram.

Re: Moving SclRvRuler1.BottomMargin by code

Posted: Thu Sep 14, 2023 12:00 pm
by fara2000
Thank you for your reply.
It seems I have difficulties to present my problem!
In the Line code you suggested,
SRichViewEdit.SetFloatPropertyEd(srvfpPPBottomMargin, NewMarginValue, True);
I need to calculate NewMarginValue so the BottomMargin(Presented By the Letter 'A' in the ScreenShut I sent) will jump just after the table item in my document. It is vital for me to do that bycode!!

Re: Moving SclRvRuler1.BottomMargin by code

Posted: Thu Sep 14, 2023 12:53 pm
by Sergey Tkachenko
In which units Y coordinates of A and B are specified? In screen pixels? Or maybe in the ruler units (I can see centimeters on your screenshot)?

Re: Moving SclRvRuler1.BottomMargin by code

Posted: Thu Sep 14, 2023 1:41 pm
by fara2000
Pixels...
when I execute the Line SclRvRuler1.BottomMargin:=SclRvRuler1.BottomMargin+1; the BottomMargin jump one pixel upword.
I need to know how many pixels there are between points A and B...
I could retrieve the itemRect of the last item(table), then it seems that I should deal with (BottomMargin-ItemRect.Bottom) in the following way
SclRvRuler1.BottomMargin:=SclRvRuler1.BottomMargin+(BottomMargin-ItemRect.Bottom)

The Bottommargin moves close to the bottom of table1 but not exactly!

Re: Moving SclRvRuler1.BottomMargin by code

Posted: Thu Sep 14, 2023 7:48 pm
by fara2000
Hello Sergey
I Got some help from samples in the demo and could write what I want
it's ok. I found the soluttion...


PageNo:=1;
PageRect:=Rich.GetPageClientRect(PageNo);
Rich.GetPageLastItemNo(PageNo,LastItemNo, Offs);
ItemPart := 0;
ItemRect := Bounds(0, 0, 0, 0);
while Rich.GetItemBounds100(Rich.RichViewEdit.RVData,LastItemNo,
ItemPartRect, FirstPageNo,
PageNo,ItemPart) do
begin
WinApi.Windows.UnionRect(ItemRect, ItemRect, ItemPartRect);
inc(ItemPart);
end;
OffsetRect(ItemRect, PageRect.Left, PageRect.Top);
RVData:=Rich.RichViewEdit.RVData;
Shift:=Rich.PageHeight100Pix-ItemRect.Bottom;
SclRvRuler22.BottomMargin:=Shift;

Thank you

Re: Moving SclRvRuler1.BottomMargin by code

Posted: Fri Sep 15, 2023 7:47 am
by Sergey Tkachenko
The idea is correct, but there may be problems with DPI.

All *100 properties of TSRichViewEdit (including GetItemBounds100 and PageHeight100Pix) are measured in pixels at 96 DPI.
Ruler.BottomMargin is measured in Ruler.UnitsProgram. As I understand, in your application, Ruler.UnitsProgram = ruPixels. In this case, Ruler.BottomMargin is measured in pixels at DPI specified in Ruler.ScreenRes, which is usually equal to the current screen DPI.

So your code will not work correctly if screen DPI <> 96.
It needs a correction:

Code: Select all

SclRvRuler22.BottomMargin:=Shift * SclRvRuler22.ScreenRes div 96;

Re: Moving SclRvRuler1.BottomMargin by code

Posted: Fri Sep 15, 2023 2:35 pm
by fara2000
Thank you. I will do that.
you are as always very brilliant...