Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6820805
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:28:07+00:00 2026-05-26T21:28:07+00:00

I have richtextbox and preview dialog. when I want to make a preview I

  • 0

I have richtextbox and preview dialog.
when I want to make a preview I want to see all the pages of the richtextbox but now I can see only the fist page many times.

please help me

char[] param = { '\n' };
string [] lines = {};

if (pd.PrinterSettings.PrintRange == PrintRange.Selection)
{
   lines = rtb.SelectedText.Split(param);
}
else
{
   lines = rtb.Text.Split(param);
}

int i = 0;
char[] trimParam = { '\r' };
foreach (string s in lines)
{
   lines[i++] = s.TrimEnd(trimParam);
}
int linesPrinted = 0;
int x = e.MarginBounds.Left;
int y = e.MarginBounds.Top;
Brush brush = new SolidBrush(rtb.ForeColor);

while (linesPrinted < lines.Length)
{
   e.Graphics.DrawString(lines[linesPrinted++],
        rtb.Font, brush, x, y);
   y += 15;
   if (y >= e.MarginBounds.Bottom)
   {
       e.HasMorePages = true;
       return;
   }
   else
   {

       e.HasMorePages = false;
   }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T21:28:08+00:00Added an answer on May 26, 2026 at 9:28 pm

    Because if you have this method in the print page even, every time that a new page is printed you read again the content of the RichTextBox :

    lines = rtb.Text.Split(param);
    

    And you start again from the beginning …

    So you have to read the RichTextBox content only in the first page …
    To resolve this problem you can for example declare a variable outside of the method :

    private int printPage = 0 ;
    

    And externalize from the method the variables :

    string [] lines = {};
    int linesPrinted = 0;
    

    The new code become (I haven’t tested it – is only a proof of concept) :

     if(printPage <= 0) {
       //First Page
       char[] param = { '\n' };
       linesPrinted = 0;
       if (pd.PrinterSettings.PrintRange == PrintRange.Selection)
       {
           lines = rtb.SelectedText.Split(param);
       }
       else
       {
           lines = rtb.Text.Split(param);
       }
      }
       int i = 0;
       char[] trimParam = { '\r' };
       foreach (string s in lines)
       {
           lines[i++] = s.TrimEnd(trimParam);
       }
    
       int x = e.MarginBounds.Left;
       int y = e.MarginBounds.Top;
       Brush brush = new SolidBrush(rtb.ForeColor);
    
       while (linesPrinted < lines.Length)
       {
           e.Graphics.DrawString(lines[linesPrinted++],
                rtb.Font, brush, x, y);
           y += 15;
           if (y >= e.MarginBounds.Bottom)
           {
               e.HasMorePages = true;
               printPage++;
               return;
           }
           else
           {
               e.HasMorePages = false;
           }
       }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've searched through related questions but can't find what I need. I have a
I have a .rtf file and want to put it in a richtextbox in
I have a RichTextBox and I want to save the text to a file.
I have a RichTextBox that I'm spewing log information to, but the RichTextBox seems
I have a RichTextBox and a button. Is there any easy way to make
It is possible to make RichTextBox have corner radius in wpf. i know it
I have a form app. inside I have a richTextBox. How to make make
Right now I have 3 RichTextBox(es) with text in them. I am taking this
If I have a RichTextBox and want output like the first line is a
Basically, I have a RichTextBox and I want to convert the formatted contents of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.