如何在C#中访问打印预览对话框的打印按钮事件 [英] How to Access Print Button Event of Print Preview Dialog in C#
本文介绍了如何在C#中访问打印预览对话框的打印按钮事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何查看打印预览对话框的打印按钮事件?
例如:
I想打印页面只有一次,当第二次用户点击打印预览对话框的打印按钮,然后我将限制用户。
How can I Check Print Preview Dialog's print Button Event?
For Example :
I wanna print the page only one time and when second time user click on Print Preview Dialog's Print Button then I will restrict the user.
推荐答案
真的不能让你的想法落后于此..正如Dave Kreskowiak所说,你的案件可能存在错误。但是我正在开发一个需要PrintPreviewDialog的项目,当点击PrintPreviewDialog的Print选项时,我需要选择打印机而不是直接打印文档。所以我设法做了
1.操作PrintPreviewDialog的打印工具条
2.向PrintDocument.PrintPage事件和PrintPreview.PrintClick事件添加处理程序
Really cant get your Idea behind this.. As Dave Kreskowiak says about the possible errors of your case. But I am working on a project where I need PrintPreviewDialog and I need to select a printer instead of direct print of document when Print option of PrintPreviewDialog is clicked. So I managed to do
1. manipulate Print Toolstrip of the PrintPreviewDialog
2. Add a Handler to PrintDocument.PrintPage event and PrintPreview.PrintClick event
Private Sub Print_btn_Click(sender As Object, e As EventArgs) Handles Print_btn.Click
Dim b As New ToolStripButton
b.Image = CType(PrintPreviewDialog1.Controls(1), ToolStrip).ImageList.Images(0)
b.ToolTipText = "Print"
b.DisplayStyle = ToolStripItemDisplayStyle.Image
AddHandler b.Click, AddressOf PrintPreview_PrintClick
CType(PrintPreviewDialog1.Controls(1), ToolStrip).Items.RemoveAt(0)
CType(PrintPreviewDialog1.Controls(1), ToolStrip).Items.Insert(0, b)
AddHandler PrintDocument1.PrintPage, AddressOf PrintDocument1_PrintPage
PrintPreviewDialog1.Document = PrintDocument1
PrintDocument1.OriginAtMargins = False
PrintPreviewDialog1.ShowDialog()
End Sub
Private Sub PrintPreview_PrintClick(sender As Object, e As EventArgs)
Try
PrintDialog1.Document = PrintDocument1
If PrintDialog1.ShowDialog() = DialogResult.OK Then
PrintDocument1.Print()
End If
Catch ex As Exception
End Try
End Sub
Private Sub PrintDocument1_PrintPage(sender As Object, e As Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
Me.BackgroundImage = WindowsApp1.My.Resources.Resources.WhiteBackground
Dim print_bmp As Bitmap = GetClientareaImage(Me)
e.Graphics.DrawImage(print_bmp, 0, 0)
End Sub
我需要打印表单客户区的图像。所以我编写了与此解决方案无关的函数GetClientareaImage()。这就是为什么我没有发布它。
I need to print the image of form's client area. So I write the function "GetClientareaImage()" which has no Relation to this solution. Thats why I am not posting it.
这篇关于如何在C#中访问打印预览对话框的打印按钮事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文