|
-
November 18th, 2010, 10:27 AM
#1
.NET Printing Predicament
EDIT: Forgot to mention: VS2010
Here's my situation:
I've done a whole lot of grabbing, formatting and relocating of data and stuck it in a RichTextBox. All good there. The formatted info needs to print. Also good. Unfortunately it is supposed to have page breaks at certain points. No biggy, I'll just use vbFormFeed.
vbFormFeed does not work with Windows printer Drivers... Great... Also, since it's .NET and not VB6, no Printer object.
My current printing method (PrintDocument) is as such:
Code:
Private Sub prtCheq_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles prtCheq.PrintPage
Static intCurrentChar As Int32
Dim font As New Font("Courier New", 10, FontStyle.Bold)
Dim intPrintAreaHeight, intPrintAreaWidth, marginLeft, marginTop As Int32
With prtCheq.DefaultPageSettings
intPrintAreaHeight = .PaperSize.Height - .Margins.Top - .Margins.Bottom
intPrintAreaWidth = .PaperSize.Width - .Margins.Left - .Margins.Right
marginLeft = 50 ' X coordinate
marginTop = 50 ' Y coordinate
End With
If prtCheq.DefaultPageSettings.Landscape Then
Dim intTemp As Int32
intTemp = intPrintAreaHeight
intPrintAreaHeight = intPrintAreaWidth
intPrintAreaWidth = intTemp
End If
Dim intLineCount As Int32 = CInt(intPrintAreaHeight / font.Height)
Dim rectPrintingArea As New RectangleF(marginLeft, marginTop, intPrintAreaWidth + 75, intPrintAreaHeight + 50)
Dim fmt As New StringFormat(StringFormatFlags.LineLimit)
Dim intLinesFilled, intCharsFitted As Int32
e.Graphics.MeasureString(Mid(txtFinal.Text, intCurrentChar + 1), font, _
New SizeF(intPrintAreaWidth, intPrintAreaHeight), fmt, _
intCharsFitted, intLinesFilled)
e.Graphics.DrawString(Mid(txtFinal.Text, intCurrentChar + 1), font, _
Brushes.Black, rectPrintingArea, fmt)
intCurrentChar += intCharsFitted
If intCurrentChar < txtFinal.Text.Length Then
e.HasMorePages = True
Else
e.HasMorePages = False
intCurrentChar = 0
End If
End Sub
Willing to ditch this whole method if need be. But I don't have a clue how I'm going to do this... perhaps something with an
Code:
If currentLine.contains(vbFormFeed) Then
'new page, page break, w/e
End If
What do?
Last edited by WileeDarklight; November 18th, 2010 at 10:36 AM.
-
November 18th, 2010, 01:23 PM
#2
Re: .NET Printing Predicament
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
|