printing richtextbox in c#
<p>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. </p>

<p>please help me</p>

<pre><code>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 &lt; lines.Length)
{
   e.Graphics.DrawString(lines[linesPrinted++],
        rtb.Font, brush, x, y);
   y += 15;
   if (y &gt;= e.MarginBounds.Bottom)
   {
       e.HasMorePages = true;
       return;
   }
   else
   {

       e.HasMorePages = false;
   }
}
</code></pre>
