CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Mar 2010
    Posts
    3

    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

  2. #2
    Join Date
    Mar 2010
    Posts
    3

    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;

  3. #3
    Join Date
    Mar 2010
    Posts
    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

  4. #4
    Join Date
    May 2010
    Posts
    2

    Re: Display page break in RichTextBox, WYSIWYG

    Hi,

    Can you please show me that code?
    I really need it , its urgent.

    Regards,
    Nidhi

  5. #5
    Join Date
    May 2010
    Posts
    2

    Re: Display page break in RichTextBox, WYSIWYG

    Quote Originally Posted by jaado View Post
    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

  6. #6
    Join Date
    Dec 2011
    Posts
    1

    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
  •  





Click Here to Expand Forum to Full Width

Featured