All I have found on the internet and VS is how to print text. And that is not very helpful in itself! Here is an example which is better than the documentation VS had, but there are still problems with how to accomodate word wrap that occurs because of the margins:
private void printDocument_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
float linesPerPage= e.MarginBounds.Height/this.RTB.Font.GetHeight(e.Graphics);
string[]lines= this.RTB.Text.Split('\n');
for(int i=0; i<linesPerPage; i++)
{
if(i==lines.Length) break;
float yPos= e.MarginBounds.Top + (i * this.RTB.Font.GetHeight(e.Graphics));
Rectangle R=new Rectangle(e.MarginBounds.Left, Convert.ToInt32(yPos), e.MarginBounds.Width, e.MarginBounds.Height);
e.Graphics.DrawString(lines, this.RTB.Font, Brushes.Red, R, new StringFormat());
}
The problem with that code is, like I said, the word wrap that the margins cause. When a string is too long it wraps which is great! But the rest of the document continues on the line that it was going to be on and it over-writes the wrapped text.
I guess my thought is that there is a better way to print. How does MS Word do it with all the different sizes of fonts and pictures?
private void printDocument_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
float linesPerPage= e.MarginBounds.Height/this.RTB.Font.GetHeight(e.Graphics);
string[]lines= this.RTB.Text.Split('\n');
for(int i=0; i<linesPerPage; i++)
{
if(i==lines.Length) break;
float yPos= e.MarginBounds.Top + (i * this.RTB.Font.GetHeight(e.Graphics));
Rectangle R=new Rectangle(e.MarginBounds.Left, Convert.ToInt32(yPos), e.MarginBounds.Width, e.MarginBounds.Height);
e.Graphics.DrawString(lines, this.RTB.Font, Brushes.Red, R, new StringFormat());
}
The problem with that code is, like I said, the word wrap that the margins cause. When a string is too long it wraps which is great! But the rest of the document continues on the line that it was going to be on and it over-writes the wrapped text.
I guess my thought is that there is a better way to print. How does MS Word do it with all the different sizes of fonts and pictures?