Page 1 of 1
prevent page break
Posted: Tue Aug 23, 2016 1:59 pm
by MrQuestion
Moin moin,
all i want to know is, how can i prevent the User to add a new Page on my Richview?
I tried so many things out...
Also the Forum is full of threads how it is possible to add a page break, but i couldnt find any of how to prevent of page break...
my last try ends up like this:
Code: Select all
procedure TFInsertControls.SRichViewEdit1PaintPage(Sender: TObject;
PageNo: Integer; PageRect, R: TRect; Canvas: TCanvas; Prepaint,
Printing: Boolean);
var
i, i2 : Integer;
begin
if SRichViewEdit1.PageCount > 1 then
begin
SRichViewEdit1.GetPageStartItemNo(2, i, i2);
if SRichViewEdit1.GetPageNo(SRichViewEdit1.ActiveEditor.RVData, i, i2) > 1 then
begin
SRichViewEdit1.DeletePage(2);
end;
end;
end;
I know there is a IgnorePagebreak somewhere in the Code, but i dont know how to use it anyway...
hope you guys can help me out...
Greetings from Germany
Sry for my bad Language
Posted: Tue Aug 23, 2016 4:06 pm
by Sergey Tkachenko
A property for ignoring page breaks is available for TRVReportHelper, not for ScaleRichView.
There is no possibility of preventing adding page breaks. Even if you disable these commands in user interface, page breaks can be added when pasting data (even a plain text, #$0C character).
So the only way is writing a code for removing page breaks. Something like this:
Code: Select all
var
i, r: Integer;
Table: TRVTableItemInfo;
rv: TCustomRichView;
begin
rv := SRichViewEdit1.RichViewEdit;
for i := 0 to rv.ItemCount-1 do
begin
rv.PageBreaksBeforeItems[i] := False;
if rv.GetItem(i) is TRVTableItemInfo then
begin
table := TRVTableItemInfo(rv.GetItem(i);
for r := 0 to table.RowCount - 1 do
table.Rows[r].PageBreakBefore := False;
end;
end;
end;
The code above removes all forced page breaks. But it does not prevent page breaking if the document does not fit to a single page.
Re: prevent page break
Posted: Wed Aug 24, 2016 8:38 am
by MrQuestion
MrQuestion wrote:
Code: Select all
procedure TFInsertControls.SRichViewEdit1PaintPage(Sender: TObject;
PageNo: Integer; PageRect, R: TRect; Canvas: TCanvas; Prepaint,
Printing: Boolean);
var
i, i2 : Integer;
begin
if SRichViewEdit1.PageCount > 1 then
begin
SRichViewEdit1.GetPageStartItemNo(2, i, i2);
if SRichViewEdit1.GetPageNo(SRichViewEdit1.ActiveEditor.RVData, i, i2) > 1 then
begin
SRichViewEdit1.DeletePage(2);
end;
end;
end;
This is fine for any Control, but when i press Enter at the last Position of Page1 then Page2 is visible.
Is there a way to delete this new page? Because my OnPaintPage doesnt help here...
Can i just remove this Letter or Item?
Posted: Wed Aug 24, 2016 9:07 am
by Sergey Tkachenko
My code removes page breaks added by "Insert Page Break" command (or loaded from files), but it does not prevent page breaks if the content does not fit the page.
The code to delete content of all pages after the page 1 is below:
Code: Select all
var
PageCount: Integer;
begin
if SRichViewEdit1.PageCount = 1 then
exit;
SRichViewEdit1.CanUpdate := False;
while SRichViewEdit1.PageCount > 1 do
begin
PageCount := SRichViewEdit1.PageCount;
SRichViewEdit1.DeletePage(SRichViewEdit1.PageCount);
if PageCount = SRichViewEdit1.PageCount then
with SRichViewEdit1.RichViewEdit do
begin
SetSelectionBounds(
ItemCount-1, GetOffsAfterItem(ItemCount-1),
ItemCount-1, GetOffsAfterItem(ItemCount-1));
SendMessage(Handle, WM_KEYDOWN, VK_BACK, 0);
end;
end;
SRichViewEdit1.CanUpdate := True;
end;
But you cannot modify document while painting its pages, the editor may crash.
Posted: Wed Aug 24, 2016 9:37 am
by MrQuestion
Code: Select all
var
PageCount: Integer;
begin
if SRichViewEdit1.PageCount = 1 then
exit;
SRichViewEdit1.CanUpdate := False;
while SRichViewEdit1.PageCount > 1 do
begin
PageCount := SRichViewEdit1.PageCount;
SRichViewEdit1.DeletePage(SRichViewEdit1.PageCount);
if PageCount = SRichViewEdit1.PageCount then
with SRichViewEdit1.RichViewEdit do
begin
SetSelectionBounds(
ItemCount-1, GetOffsAfterItem(ItemCount-1),
ItemCount-1, GetOffsAfterItem(ItemCount-1));
SendMessage(Handle, WM_KEYDOWN, VK_BACK, 0);
end;
end;
SRichViewEdit1.CanUpdate := True;
end;
Works fine, thanks so far.
Posted: Thu Aug 25, 2016 9:55 am
by MrQuestion
Huhu,
i have found a smaller Answer to my Problem:
Code: Select all
if SRichViewEdit1.PageCount = 1 then
begin
exit;
end;
//
SRichViewEdit1.RichViewEdit.Undo;
This helps very much, because there are no problems with deleting Content by inserting an Item between (or before) other Items that will generate a new Page.
(The Item will be pushed to Page 2 wich will be deleted)
Thank you anyway.