Home > Net >  Questions about the PrintDocument print
Questions about the PrintDocument print

Time:09-18

Everybody is good, the degree of this run to pd. The Print () an error, please help to see

Imports System. IO
Imports System. Drawing. Printing
Imports System. Text
Imports System. Drawing
Public Class Form2

Private sr As StringReader
'Private sr As String
Private Sub Button1_Click (sender As Object, As EventArgs e) Handles for. Click
Dim sb As New StringBuilder ()

Sb. Append (" parking lot management system \ n ")

Sb. Append (" * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * \ n ")

Print (sb. ToString ())
End Sub
The Public Function Print (ByVal STR As String) As Boolean
Dim the result As a Boolean=True
'the sr=TextBox1. Text

The sr=New StringReader (STR. ToString ())
Dim pd As PrintDocument=New PrintDocument ()
Dim pageSize As New PaperSize (the "First custom size", 600, 600)
Pd. PrintController=New System. Drawing. Printing. StandardPrintController ()
Pd. DefaultPageSettings. Margins. Top=2
Pd. DefaultPageSettings. Margins. Left=0
Pd. DefaultPageSettings. PaperSize. Width=320
Pd. DefaultPageSettings. PaperSize. Height=5150
Pd. PrinterSettings. PrinterName=pd. DefaultPageSettings. PrinterSettings. PrinterName

Pd. OriginAtMargins=True
Dim MARGIN As Margins=New Margins (1, 1, 1, 1)
Pd. DefaultPageSettings. Margins=MARGIN


AddHandler pd. PrintPage AddressOf Me. Pd_PrintPage

Try
Pd. Print ()
Catch the ex As Exception
Result=False
The Finally
If the sr IsNot Nothing Then sr. The Close ()
End the Try

Return the result
End the Function

Private Sub pd_PrintPage (ByVal sender As Object, ByVal ev As PrintPageEventArgs)
Dim printFont As the Font=New Font (" Arial ", 9)
Dim linesPerPage As Single=0
Dim yPos As Single=0
Dim the count As Integer=0
Dim leftMargin As Single=ev. MarginBounds. Left
Dim topMargin As Single=ev. MarginBounds. Top
Dim line As String=""
LinesPerPage=ev. MarginBounds. Height/printFont GetHeight (ev) Graphics)
'the line=sr. ReadLine ())!=null)
MsgBox (linesPerPage)

While the count & lt; LinesPerPage And ((line=sr. ReadLine ()) & lt; & gt; "")

YPos=topMargin + (count * printFont GetHeight (ev) Graphics))
Ev. Graphics. DrawString (line, printFont, Brushes. Black, leftMargin, yPos, New StringFormat ())

Count +=1
End While

If the line IsNot Nothing Then
Ev. HasMorePages=True
The Else
Ev. HasMorePages=False
End the If
End Sub


The End of the Class
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Run to pd. The Print () error: "System.Com ponentModel. Win32Exception" type of untreated anomalies in the System. Drawing. The DLL
  • Related