Created
July 31, 2012 19:20
-
-
Save gosukiwi/3219706 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void printDocument_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs ev) | |
{ | |
float linesPerPage = 0; | |
float yPosition = 0; | |
int count = 0; | |
float leftMargin = ev.MarginBounds.Left; | |
float topMargin = ev.MarginBounds.Top; | |
string line = null; | |
Font printFont = txtRazonSocial.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 = _printStringReader.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(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment