VB.net - 打印图片框
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/46846738/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
VB.net - printing picture box
提问by Fyer-Zero
So I have made a drawing in a picture box. I draw in a BMP then load the BMP in the picturebox using this code:
所以我在画框里画了一张图。我在 BMP 中绘制,然后使用以下代码将 BMP 加载到图片框中:
PcbNetwerk.BackgroundImage = bmpNO
Then I try to print using the following code:
然后我尝试使用以下代码打印:
Dim WithEvents PrintDoc As New PrintDocument()
Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDoc.PrintPage
e.Graphics.DrawImage(PcbNetwerk.Image, 0, 0)
End Sub
Private Sub BtnPrintNetwerk_Click(sender As Object, e As EventArgs) Handles BtnPrintNetwerk.Click
If PrintDialog1.ShowDialog = DialogResult.OK Then
PrintDocument1.Print()
End If
End Sub
but it only results in blank prints. Also when I select a paper printer I only end up with a empty PDF file. I have been searching for a solution for hours now but everything I finds leads back to the same sort of code and I get the same results (blank pages and in some cases my program even crashes). The size I want to print to is A3 landscape format.
但它只会导致空白打印。此外,当我选择纸质打印机时,我最终只会得到一个空的 PDF 文件。我几个小时以来一直在寻找解决方案,但我找到的所有内容都会返回到相同类型的代码,并且得到相同的结果(空白页面,在某些情况下我的程序甚至崩溃)。我要打印的尺寸是 A3 横向格式。
采纳答案by Fyer-Zero
so picturebox1.image resulted in an empy file. to fix this problem I created:
所以 picturebox1.image 产生了一个 empy 文件。为了解决我创建的这个问题:
Public Netwerkoverzicht As Image
Public Netwerkoverzicht As Image
in the public class of my form.
在我的表格的公共课上。
Then I saved the bmp file I generate in one of my subs to this image public I made and use the following code where I replace PcbNetwerk.image with Netwerkwerkoverzicht
然后我将我在我的一个 subs 中生成的 bmp 文件保存到我制作的这张公共图像中,并使用以下代码将 PcbNetwerk.image 替换为 Netwerkwerkoverzicht
Dim WithEvents PrintDoc As New PrintDocument()
Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDoc.PrintPage
e.Graphics.DrawImage(Netwerkoverzicht, 0, 0)
End Sub

