我们正在制作明信片,我需要将图像放在第二页上,因此打印机将进行双面打印,我们将在一侧显示图像,在另一侧显示文本
Imports System.Drawing
Imports System.Drawing.Printing
Public Class trial : Inherits Printing.PrintDocument
Dim text As String
Dim font As Font
Dim leftText As String
Dim pic As Image
Dim paper As PaperSize
Dim printNewPage As Boolean = True
Dim page1 As Boolean = True
Sub New(ByVal lefty As String, ByVal nam As String, ByVal add As String, ByVal cit As String, ByVal zi As String, ByVal pi As Image, ByVal ps As PaperSize)
font = New Font("Arial", 12)
text = nam & Environment.NewLine & add & Environment.NewLine & cit & ", IN" & Environment.NewLine & zi
paper = ps
leftText = lefty
pic = pi
End Sub
Protected Overrides Sub onPrintPage(ByVal e As Printing.PrintPageEventArgs)
MyBase.OnPrintPage(e)
MyBase.DefaultPageSettings.PaperSize = paper
If page1 Then
printLeft(e)
printright(e)
End If
If printNewPage Then
e.HasMorePages = True
printFront(e)
Else
e.HasMorePages = False
End If
End Sub
Private Sub printLeft(ByVal e As Printing.PrintPageEventArgs)
Dim area As RectangleF = New RectangleF(20, 20, 150, 400)
Dim format As StringFormat = New StringFormat(StringFormatFlags.LineLimit)
e.Graphics.DrawString(leftText, font, Brushes.Black, area, format)
e.Graphics.DrawLine(Pens.Black, 200, 20, 200, 399)
End Sub
Private Sub printright(ByVal e As Printing.PrintPageEventArgs)
Dim area As RectangleF = New RectangleF(200, 20, 200, 400)
Dim format As StringFormat = New StringFormat(StringFormatFlags.LineLimit)
e.Graphics.DrawString(text, font, Brushes.Black, area, format)
page1 = False
End Sub
Private Sub printFront(ByVal e As Printing.PrintPageEventArgs)
MyBase.OnPrintPage(e)
Dim area As RectangleF = New RectangleF(20, 500, 400, 400)
e.Graphics.DrawImage(pic, area)
printNewPage = False
End Sub
End Class
答案 0 :(得分:0)
如果打印机默认设置为双面打印,则打印多页文档时将自动进行双面打印。您需要查看PrintPageEventArgs.HasMorePages属性。打印第一页后,您需要将此设置为True。