Click here to Skip to main content
15,920,111 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
hi every one
in my application i used richbox to let the user write on it and i used
print dialge window and printview dialge window
but when i press printview buttom not the all text displayed in window
so i wonder if there mathmatical relation between font size and paper size(A4 .......) and margines to determine how many character must be in every line and how many line in the one page .

thanks to all.
Posted

1 solution

Well, my friend. try this in PrintPage event of your PrintDocument object:

<br />
private int LastPrintedLine = 0;<br />
<br />
private void PrintDocument_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)<br />
        {<br />
            SizeF LineSize = new SizeF();<br />
<br />
            PointF UpperLeftPoint = new PointF(e.MarginBounds.X, e.MarginBounds.Y);<br />
<br />
            RectangleF Rect = new RectangleF();<br />
<br />
            while (true)<br />
            {<br />
                LineSize = e.Graphics.MeasureString(TextHolder.Lines[LastPrintedLine], TextHolder.Font);<br />
<br />
                UpperLeftPoint.Y += Rect.Height;<br />
<br />
                Rect.Location = UpperLeftPoint;<br />
<br />
                Rect.Width = e.MarginBounds.Width;<br />
<br />
                int LineSegments = (int)(LineSize.Width / e.MarginBounds.Width) + 1;<br />
<br />
                Rect.Height = LineSize.Height * LineSegments;<br />
<br />
                e.Graphics.DrawString(TextHolder.Lines[LastPrintedLine], TextHolder.Font,<br />
                                      new SolidBrush(Color.Black), Rect);<br />
<br />
                LastPrintedLine++;<br />
<br />
                if (UpperLeftPoint.Y > e.MarginBounds.Height) break;<br />
<br />
<br />
                if (LastPrintedLine == TextHolder.Lines.Length)<br />
                {<br />
                    e.HasMorePages = false;<br />
                    break;<br />
                }<br />
                else<br />
                    e.HasMorePages = true;<br />
            } <br />
        }<br />


-------------------------
Regards

H.Maadani
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900