PrintPreviewDialog由两个不同的页面事件 [英] PrintPreviewDialog By Two Different Page Event
本文介绍了PrintPreviewDialog由两个不同的页面事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
专家,我需要一些如何实现这一目标的指导方针。
我在button_click事件中创建了printpreviewdialog。但问题是
,我一次只能预览一个文件。是否可以在我的printpriviewdialog中将第二个printpageevents作为第二页调用
?
私有 Sub Button1_Click( ByVal 发件人作为系统。对象, ByVal e As System.EventArgs)句柄 Button1.Click
Dim prn As 新 Printing.PrintDocument
Dim 预览作为 新 PrintPreviewDialog
AddHandler prn.PrintPage, AddressOf _Invoice
Preview.Document = prn
Preview.PrintPreviewControl.Zoom = 1
Preview.Showdialog
结束 Sub
私人 Sub _Invoice( ByVal sender As 对象, ByVal args 作为 Printing.PrintPageEventArgs )
args.Graphics.PageUnit = GraphicsUnit.Millimeter
args.Graphics.DrawString( Invoice,新字体( Arial Narrow, 12 ,FontStyle.Bold),Brushes.Black, 10 , 5 )
结束 Sub
私人 子 _DO( ByVal sender 作为 对象, ByVal args As Printing.PrintPageEventArgs)
args.Graphics.PageUnit = GraphicsUnit.Millimeter
args.Graphics.DrawString( DO,新字体( Arial Narrow, 12 ,FontStyle.Bold),Brushes.Black , 10 , 5 )
结束 Sub
解决方案
经过一番研究,我已经完成了这项工作并且适合我。
私有 Sub Button1_Click( ByVal sender 作为系统。对象, ByVal e As System.EventArgs)句柄 Button1.Click
Dim 预览< span class =code-keyword>作为 新 PrintPreviewDialog
Dim prn 作为 新 Printing.PrintDocument
AddHandler prn.PrintPage, AddressOf _Invoice
使用预览
.Do cument = prn
.WindowState = FormWindowState.Maximized
.Document.DefaultPageSettings.PaperSize = New System.Drawing.Printing.PaperSize( A4, 827 , 1169 )
.PrintPreviewControl.Zoom = 1
.Document = prn
.ShowDialog( )
结束 使用
结束 Sub
私有 Sub _Invoice( ByVal sender As 对象, ByVal args 作为 Printing.PrintPageEve ntArgs)
args.Graphics.DrawString( INVOICE,新字体( Arial, 12 ,FontStyle.Bold),Brushes.Black, 20 , 20 )
args.HasMorePages = True
Dim prn 作为 Printing.PrintDocument = sender
RemoveHandler prn.PrintPage, AddressOf _Invoice
AddHandler prn.PrintPage, AddressOf _DO
退出 Sub
结束 子跨度>
私有 Sub _DO( ByVal 发件人作为 对象, ByVal args As Printing.PrintPageEventArgs)
args.Graphics.DrawString( DO,新字体( Arial, 12 ,FontStyle.Bold),Brushes.Black, 20 , 20 )
结束 子跨度>
Hi expert, i need some guideline on how to achieve this.
I have created printpreviewdialog in button_click event. But the problem
is, im able to preview only one documents at a time. Is it posible for me
to call the second printpageevents as second page in my printpriviewdialog?.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim prn As New Printing.PrintDocument
Dim Preview As New PrintPreviewDialog
AddHandler prn.PrintPage, AddressOf _Invoice
Preview.Document = prn
Preview.PrintPreviewControl.Zoom = 1
Preview.Showdialog
End Sub
Private Sub _Invoice(ByVal sender As Object, ByVal args As Printing.PrintPageEventArgs)
args.Graphics.PageUnit = GraphicsUnit.Millimeter
args.Graphics.DrawString("Invoice", New Font("Arial Narrow", 12, FontStyle.Bold), Brushes.Black, 10, 5)
End Sub
Private Sub _DO(ByVal sender As Object, ByVal args As Printing.PrintPageEventArgs)
args.Graphics.PageUnit = GraphicsUnit.Millimeter
args.Graphics.DrawString("DO", New Font("Arial Narrow", 12, FontStyle.Bold), Brushes.Black, 10, 5)
End Sub
解决方案
After some research, I have done this and works for me.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim Preview As New PrintPreviewDialog Dim prn As New Printing.PrintDocument AddHandler prn.PrintPage, AddressOf _Invoice With Preview .Document = prn .WindowState = FormWindowState.Maximized .Document.DefaultPageSettings.PaperSize = New System.Drawing.Printing.PaperSize("A4", 827, 1169) .PrintPreviewControl.Zoom = 1 .Document = prn .ShowDialog() End With End Sub Private Sub _Invoice(ByVal sender As Object, ByVal args As Printing.PrintPageEventArgs) args.Graphics.DrawString("INVOICE", New Font("Arial", 12, FontStyle.Bold), Brushes.Black, 20, 20) args.HasMorePages = True Dim prn As Printing.PrintDocument = sender RemoveHandler prn.PrintPage, AddressOf _Invoice AddHandler prn.PrintPage, AddressOf _DO Exit Sub End Sub Private Sub _DO(ByVal sender As Object, ByVal args As Printing.PrintPageEventArgs) args.Graphics.DrawString("D.O", New Font("Arial", 12, FontStyle.Bold), Brushes.Black, 20, 20) End Sub
这篇关于PrintPreviewDialog由两个不同的页面事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文