|
-
March 30th, 2010, 07:08 AM
#1
Display page break in RichTextBox, WYSIWYG
Hi everyone,
After googling the web and trying different approaches to this problem I now turn to you.
My problem is this: I am in the early stage of developing a specialized word processor and I am using RichTextBox as editor. I would like to display the RichTextBox as wide as writable area of paper - that is, paperwidth excluding margins. And I would like to display a dotted line at the position where the writable area of the paper ends. And this is where my problems start.
I've tried to set the WYSIWIG mode as described i numerous articles but when I calculate number of lines that fit in my RichTextBox the result will never be the same as displayed in print preview.
To calculate numer of lines that fit in RichTextBox I fetch graphics object from default printer settings and divide it's printable area with GetHeight(printerGraphics) of current font.
When comparing layout of text in RichTextBox with text rendered by RichtTextBox in print preview it looks like line spacing in print preview is lower than line spacing displayed in RichTextBox.
If anybody has a solution for this, an implementation of their own or other hints that will point me in right direction I would be so happy.
/
Jan Adolfsson
-
March 30th, 2010, 02:42 PM
#2
Re: Display page break in RichTextBox, WYSIWYG
This is how my code in the richtextbox looks like:
float widthInPixels = float.MinValue;
float heightInPixels = float.MinValue;
float printAreaWidth = printerSettings.DefaultPageSettings.Bounds.Width - printerSettings.DefaultPageSettings.Margins.Left - printerSettings.DefaultPageSettings.Margins.Right;
float printAreaHeight = printerSettings.DefaultPageSettings.Bounds.Height - printerSettings.DefaultPageSettings.Margins.Top - printerSettings.DefaultPageSettings.Margins.Bottom;
using (Graphics rtbGraphics = CreateGraphics())
{
widthInPixels = (printAreaWidth / 100.0f ) * rtbGraphics.DpiX;
heightInPixels = (printAreaHeight / 100.0f) * rtbGraphics.DpiY;
}
Graphics printerGraphics = printerSettings.CreateMeasurementGraphics();
float fontHeight = Font.GetHeight(printerGraphics);
_nrOfRowsOnPage = (int)(printAreaHeight / fontHeight);
_printerDC = printerGraphics.GetHdc();
printAreaWidth = printAreaWidth * 14.4f;
Win32API.SendMessage(Handle, Win32API.EM_SETTARGETDEVICE, _printerDC.ToInt32(), new IntPtr((int)printAreaWidth));
Width = (int)widthInPixels;
-
April 8th, 2010, 06:13 AM
#3
Re: Display page break in RichTextBox, WYSIWYG
I finally found a solution to this problem.
First a fill the richtextbox with lines. Then I use the formatrange method to get character index of last character that fit on the page and recalculate this to number of lines. Then I multiply number of lines with font height and I think I have the right position for the page break line.
If you find a better solution please let me know.
/jan Adolfsson
-
May 6th, 2010, 03:50 AM
#4
Re: Display page break in RichTextBox, WYSIWYG
Hi,
Can you please show me that code?
I really need it , its urgent.
Regards,
Nidhi
-
May 7th, 2010, 11:41 PM
#5
Re: Display page break in RichTextBox, WYSIWYG
 Originally Posted by jaado
I finally found a solution to this problem.
First a fill the richtextbox with lines. Then I use the formatrange method to get character index of last character that fit on the page and recalculate this to number of lines. Then I multiply number of lines with font height and I think I have the right position for the page break line.
If you find a better solution please let me know.
/jan Adolfsson
Can you please send me code? I really need it for my project
Thanks for your help
-
December 29th, 2011, 03:03 PM
#6
Re: Display page break in RichTextBox, WYSIWYG
Me too.. please..
Can you please send me code? I really need it for my project
Thanks for your help
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|