在VB.Net中打印问题 [英] Printing issue in VB.Net

查看:82
本文介绍了在VB.Net中打印问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个非常基本的打印代码,如下所示

 私有  Sub  Button1_Click( ByVal  sender  As  System。对象 ByVal  e  As  System.EventArgs)句柄 Button1.Click 
.PrintDialog1.PrinterSettings = .PrintDocument1.PrinterSettings
如果 Me .PrintDialog1.ShowDialog() = Windows.Forms.DialogResult.OK)然后

.PrintDocument1。 PrinterSettings = .PrintDialog1.PrinterSettings
.PrintDocument1.Print()

结束 如果

结束 Sub

私人 Sub PrintDocument1_PrintPage( ByVal sender As 对象 ByVal e 作为 System.Drawing.Printing.PrintPageEventArgs)句柄 PrintDocument1.PrintPage
MsgBox( 打印


结束









这是有效的正如预期的那样,当我用一个按钮来写新的表格来开始打印时,然而,当我我用另一种形式称呼这个完全相同的方法,有许多其他功能(独立于打印件),它会出现以下错误:



SEHException:外部元素抛出异常



异常来自Me.PrintDocument1.Print()



我已经尝试了一切,包括从PrintPage方法中删除整个代码(如上所示)



有没有人遇到类似的问题?关于它所讨论的外部元素绝对不知道。

请帮助!!

解决方案

也许这可以帮助???



如果Me.PrintDocument1.PrinterSettings.IsValid那么

Me.PrintDocument1.Print()

Else

MessageBox.Show(打印机无效。)

结束如果



你们全部使用打印对话框中的打印机设置。可能是打印机不支持某些设置。



只是一个想法,但它并没有真正解释为什么它在某些情况下有效...

I''ve written a very basic code of printing as below

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
       Me.PrintDialog1.PrinterSettings = Me.PrintDocument1.PrinterSettings
    If (Me.PrintDialog1.ShowDialog() = Windows.Forms.DialogResult.OK) Then

        Me.PrintDocument1.PrinterSettings = Me.PrintDialog1.PrinterSettings
        Me.PrintDocument1.Print()

    End If

End Sub

   Private Sub PrintDocument1_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
  MsgBox("Going to print")


    End Sub





This is working as expected, when I write in a new form with just one button to intiate printing, However, when I''m calling this exactly same method in another form, with lot of other functionality (independent of printing piece), it gives following error:

SEHException: "External element has thrown an exception"

The exception comes at the point "Me.PrintDocument1.Print()"

I''ve tried everything including removing entire code from PrintPage method (as shown above)

Has anybody faced similar issue? There is absolutely no idea on what external element it is talking about.
Please help!!

解决方案

Maybe this can help???

If Me.PrintDocument1.PrinterSettings.IsValid then
Me.PrintDocument1.Print()
Else
MessageBox.Show("Printer is invalid.")
End If

You''re using all printersettings from the print dialog. Could be that some setting is not supported by the printer.

Just an idea, but it doesn''t really explain why it works in some cases...


这篇关于在VB.Net中打印问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆