Click here to Skip to main content
15,893,994 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs ev)
     {
         string strText = this.richTextBox2.Text;
         StreamReader myReader = new StreamReader(strText);
         float linesPerPage = 0;
         float yPosition = 0;
         int count = 0;
         float leftMargin = ev.MarginBounds.Left;
         float topMargin = ev.MarginBounds.Top;
         string line = null;
         Font printFont = this.richTextBox1.Font;
         SolidBrush myBrush = new SolidBrush(Color.Black);
         // Work out the number of lines per page, using the MarginBounds.
         linesPerPage = ev.MarginBounds.Height / printFont.GetHeight(ev.Graphics);
         // Iterate over the string using the StringReader, printing each line.
         while (count < linesPerPage && ((line = myReader.ReadLine()) != null))
         {
             // calculate the next line position based on the height of the font according to the printing device
             yPosition = topMargin + (count * printFont.GetHeight(ev.Graphics));
             // draw the next line in the rich edit control
             ev.Graphics.DrawString(line, printFont, myBrush, leftMargin, yPosition, new StringFormat());
             count++;
         }
         // If there are more lines, print another page.
         if (line != null)
             ev.HasMorePages = true;
         else
             ev.HasMorePages = false;
         myBrush.Dispose();
     }
Posted
Comments
[no name] 5-Jun-14 6:25am    
Why is there just a code dump here? And, why does your code dump not have anything to do with the title of your posting?

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