|
-
May 2nd, 2010, 12:45 PM
#1
Thread Starter
Addicted Member
print multiple pages based off size of file.
Hey guys,
I have a question regarding multiple page printing. I know that it has to do with e.HasMorePages. I know that there has to be a condition that sets that flag to true and back to false or you get caught in a never ending print page loop. However, I have no idea where in my simple little print block here to implement that. Can someone give me a suggestion?
As you can see I'm just printing a readline. Sometimes the file extends past a single page though depending on circumstances.
Code:
Dim strReader As StreamReader
strReader = File.OpenText("auditlog.txt")
Dim x As Integer = 10
Dim y As Integer = 10
Do While strReader.Peek <> -1
e.Graphics.DrawString(strReader.ReadLine, New Font("Times New Roman", _
10, FontStyle.Regular), Brushes.Black, x, y)
y += 12
Loop
Thanks guys
Abrium
Asking the beginners questions so you don't have to!
If by chance hell actually froze over and I some how helped you... Please rate.
-
May 2nd, 2010, 01:00 PM
#2
Re: print multiple pages based off size of file.
try this:
vb Code:
Public Class Form1
Private printString As String
Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
Dim charsFitted As Integer
Dim linesFilled As Integer
e.Graphics.MeasureString(printString, New Font("Times New Roman", 10, FontStyle.Regular), e.PageBounds.Size, Drawing.StringFormat.GenericTypographic, charsFitted, linesFilled)
e.Graphics.DrawString(printString, New Font("Times New Roman", 10, FontStyle.Regular), Brushes.Black, e.PageBounds.Left, e.PageBounds.Top)
printString = printString.Substring(charsFitted)
If printString <> "" Then
e.HasMorePages = True
Else
e.HasMorePages = False
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
printString = io.file.readalltext("auditlog.txt")
PrintDocument1.Print()
End Sub
End Class
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
May 2nd, 2010, 01:18 PM
#3
Thread Starter
Addicted Member
Re: print multiple pages based off size of file.
where are charsFitted and linesFilled populated at? I'm trying to implement this and not having a lot of luck. I tried to merge the code together. This is what I have.
Code:
Dim strReader As StreamReader
strReader = File.OpenText("auditlog.txt")
Dim moreLines As String = ""
Dim x As Integer = 10
Dim y As Integer = 10
Do While strReader.Peek <> -1
e.Graphics.MeasureString(strReader.ReadLine, New Font("Times New Roman", 10, FontStyle.Regular _
), e.PageBounds.Size, Drawing.StringFormat.GenericTypographic _
, x, y)
e.Graphics.DrawString(strReader.ReadLine, New Font("Times New Roman", _
10, FontStyle.Regular), Brushes.Black, x, y)
y += 12
moreLines = moreLines.Substring(x)
If moreLines <> "" Then
e.HasMorePages = True
Else
e.HasMorePages = False
End If
moreLines = ""
Loop
I am starting to get the idea that the e.HasMorePages can't be in a loop at all.... Just a hunch, lol.
Abrium
Asking the beginners questions so you don't have to!
If by chance hell actually froze over and I some how helped you... Please rate.
-
May 2nd, 2010, 01:22 PM
#4
Re: print multiple pages based off size of file.
you have to pass the whole of the text file, then truncate it after printing a page, depending on charsFitted which along with linesFilled (which isn't used in my example) are passed in the measurestring arguments byref so they return a value
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
May 2nd, 2010, 02:00 PM
#5
Thread Starter
Addicted Member
Re: print multiple pages based off size of file.
Ok, I got it to where the charsFitted and linesFilled are populated now its just looping. Do I need to trim off what is printed before checking if charsfitted <> "" again?
Code:
Dim strReader As StreamReader
strReader = File.OpenText("auditlog.txt")
Dim docLines As String = ""
Dim x As Integer = 10
Dim y As Integer = 10
Dim charsFitted As Integer
Dim linesFilled As Integer
Do While strReader.Peek <> -1
docLines = docLines & strReader.ReadLine & vbCrLf
Loop
strReader.Close()
MsgBox(docLines)
e.Graphics.MeasureString(docLines, New Font("Times New Roman", 10, FontStyle.Regular _
), e.PageBounds.Size, Drawing.StringFormat.GenericTypographic _
, charsFitted, linesFilled)
e.Graphics.DrawString(docLines, New Font("Times New Roman", _
10, FontStyle.Regular), Brushes.Black, e.PageBounds.Left, _
e.PageBounds.Top)
docLines = docLines.Substring(charsFitted)
If docLines <> "" Then
e.HasMorePages = True
Else
e.HasMorePages = False
End If
End Sub
Abrium
Asking the beginners questions so you don't have to!
If by chance hell actually froze over and I some how helped you... Please rate.
-
May 2nd, 2010, 02:06 PM
#6
Re: print multiple pages based off size of file.
the way you've got it it loads the whole file into docLines every time the printPage sub runs, so it'll loop forever.
when you set e.hasmorepages = true, what happens is that after exiting the printPage sub it runs the printPage sub again
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|