By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,459 Members | 1,472 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,459 IT Pros & Developers. It's quick & easy.

About PrintDocument

P: n/a
Hello!

In the main form I have a multiline textbox where I can enter text. This is
named textBoxEdit.
Below I have an eventHandler for event BeginPrint called OnBeginPrint for
object PrintDocument and
an event handler for event PrintPage here called OnPrintPage for object
PrintDocument.

In the eventhandler OnBeginPrint it seems to me that these statements
surrounded with []
[int i = 0;
char[] trimParam = { '\r' };

foreach (string s in lines)
lines[i++] = s.TrimEnd(trimParam);]

can be removed because it works just the same without them.
The purpose with these statement is to remove carrige return.
Can somebody explain why these statement which remove carrige return for
every line has no effect
on the text that is printed.
private void OnBeginPrint(object sender, PrintEventArgs e)
{
char[] param = { '\n' };
lines = textBoxEdit.Text.Split(param);

int i = 0;
char[] trimParam = { '\r' };

foreach (string s in lines)
lines[i++] = s.TrimEnd(trimParam);
}

private void OnPrintPage(object sender, PrintPageEventArgs e)
{
int x = 20, y = 20;

while (linesPrined < lines.Length) //antal rader att printa
{
e.Graphics.DrawString(lines[linesPrined++],
new Font("Arial", 10), Brushes.Black, x, y+=15);

if (y <= e.PageBounds.Height - 80)
{
e.HasMorePages = true;
return;
}
}

linesPrined = 0;
e.HasMorePages = false;
}

//Tony
Jul 10 '08 #1
Share this Question
Share on Google+
1 Reply


P: n/a
On Thu, 10 Jul 2008 09:30:00 -0700, Tony Johansson
<jo*****************@telia.comwrote:
[...]
The purpose with these statement is to remove carrige return.
Can somebody explain why these statement which remove carrige return for
every line has no effect
on the text that is printed.
I'm not even sure that DrawString() does anything with a carriage return
in the string. But assuming it did, the carriage returns would appear
only at the end of each string, and thus would have no effect on the
actual output from DrawString() for each line.

I find it a bit odd that the code you posted is doing all that parsing
anyway. Given that the text is coming from a TextBox (apparently), I
would have thought that using the Lines property would be more appropriate
for this purpose.

Pete
Jul 10 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.