Printing text (text is clipped)

Mark Wills

Member
Joined
Jul 11, 2004
Messages
13
Location
Worldwide
Programming Experience
10+
Hi there.

I am working on a VB.Net application (WinForms) and all is working fine. I'm just putting the finishing touches to it, and am now working on a Print function.

The application is a code editor, and of course, one of the facilities is to be able to print the code that one has written. I have consulted the MSDN documentation, and, with it's help, I have managed to write a well behaved routine that does indeed print to the printer, using the PrintDocument_PrintPage event.

However, there is one problem - some lines that are longer than the page width are 'clipped' and thus there is test missing from the printout.

I need someway to know if a line of text is too long, and if so, at which point do I split the string?

I have seen a reference to MeasureString on this page: http://www.startvbdotnet.com/controls/printdialog1.aspx

However, the code as presented on the above site is broken (there is part of a line missing) and I can't reconstruct his code.

Can anyone suggest a method providing a printout without text being clipped? The text should ust wrap to the next line.

Many thanks

Mark Wills UK
 
Moved to Printing forum. (btw, the '_' end-of-line chars in that article code examples signifies that code continues next line, this is recognized also in VB code editor, I think they call it line-continuation character. So for me those code examples appears complete at any screen resolution.)
 
Hi John,

Yes, but check the end of his code:

' print the text to the page
intCurrentChar += intCharsFitted
'advancing the current char to the last char printed on this page
< TextBox1.Text.Length Then

If intCurrentChar e.HasMorePages=True
'HasMorePages tells the printing module whether another PrintPage event should be fired
Else
e.HasMorePages = False

That isn't right!
 
Not have read aaaaaaall that code, I think that should read:
If intCurrentChar < richTextBox1.Text.Length Then
e.HasMorePages=True
else
 
Ok, thanks John, I'll give that a try.

I must admit, I looked at the code and thought "Er, yeah, ok, right!"

Mark.
 
Back
Top