在 vb 中打印带有图像的可滚动面板
printing scrollable panel with image inside in vb
大家好。我在打印可滚动面板中的图像时遇到问题。谁能帮我解决这个问题?
我想先调整图像的大小(以便它适合 8.5 x 11" 的纸张),然后在打印预览中显示它然后打印它
就我而言,我有一个带有面板 (dock=fill) 的表单 (form1),我想在其中打印图像(2 张图像)。但是,图像打印的触发器是下一种形式
在 btnnext(form1)
Form2.Show()
Me.Hide()
打印代码在form2中。我是 vb 的新人,我对打印可滚动面板一无所知。我在其他论坛上尝试了不同的代码,但它并没有打印出整个图像,而只打印了表格的屏幕截图。如有任何回复,我们将不胜感激。非常感谢
Public Class Form2
Private WithEvents pd As New Printing.PrintDocument
Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
Using bmp As New Bitmap(Form1.pb1.Width, Form1.pb1.Height)
Form1.panel1.DrawToBitmap(bmp, New Rectangle(0, 0, Form1.pb1.Width, Form1.pb1.Height))
e.Graphics.DrawImage(bmp, e.MarginBounds)
End Using
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
PrintDocument1.Print()
End Sub
End Class
-
^它只打印您在屏幕上看到的内容。不是整个面板..
基本上,保持一切相同,但不是在整个页面上打印整个第一张图像,而是打印第二张图像,使其位置和大小相对于 MarginBounds
Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
Using bmp As New Bitmap(Form1.pb1.Width, Form1.pb1.Height)
Form1.pb1.DrawToBitmap(bmp, New Rectangle(0, 0, Form1.pb1.Width, Form1.pb1.Height))
'Print pb1 to fill the whole page
e.Graphics.DrawImage(bmp, e.MarginBounds)
End Using
Using bmp2 As New Bitmap(Form1.pb2.Width, Form1.pb2.Height)
Form1.pb2.DrawToBitmap(bmp2, New Rectangle(0, 0, Form1.pb2.Width, Form1.pb2.Height))
Dim x as Double = Form1.pb2.Location.X - Form1.pb1.Location.X
x = x * e.MarginBounds.Width / Form1.pb1.Width
x = x + e.MarginBounds.X
Dim y as Double = Form1.pb2.Location.Y - Form1.pb1.Location.Y
y = y * e.MarginBounds.Height / Form1.pb1.Height
y = y + e.MarginBounds.Y
Dim width as Double = Form1.pb2.width
width = width * e.MarginBounds.Width / Form1.pb1.Width
Dim height as Double = Form1.pb2.Height
height = height * e.MarginBounds.Height / Form1.pb1.Height
e.Graphics.DrawImage(bmp2, New Rectangle(x, y, width, height))
End Using
End Sub
大家好。我在打印可滚动面板中的图像时遇到问题。谁能帮我解决这个问题?
我想先调整图像的大小(以便它适合 8.5 x 11" 的纸张),然后在打印预览中显示它然后打印它
就我而言,我有一个带有面板 (dock=fill) 的表单 (form1),我想在其中打印图像(2 张图像)。但是,图像打印的触发器是下一种形式
在 btnnext(form1) Form2.Show() Me.Hide()
打印代码在form2中。我是 vb 的新人,我对打印可滚动面板一无所知。我在其他论坛上尝试了不同的代码,但它并没有打印出整个图像,而只打印了表格的屏幕截图。如有任何回复,我们将不胜感激。非常感谢
Public Class Form2
Private WithEvents pd As New Printing.PrintDocument
Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
Using bmp As New Bitmap(Form1.pb1.Width, Form1.pb1.Height)
Form1.panel1.DrawToBitmap(bmp, New Rectangle(0, 0, Form1.pb1.Width, Form1.pb1.Height))
e.Graphics.DrawImage(bmp, e.MarginBounds)
End Using
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
PrintDocument1.Print()
End Sub
End Class
- ^它只打印您在屏幕上看到的内容。不是整个面板..
基本上,保持一切相同,但不是在整个页面上打印整个第一张图像,而是打印第二张图像,使其位置和大小相对于 MarginBounds
Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
Using bmp As New Bitmap(Form1.pb1.Width, Form1.pb1.Height)
Form1.pb1.DrawToBitmap(bmp, New Rectangle(0, 0, Form1.pb1.Width, Form1.pb1.Height))
'Print pb1 to fill the whole page
e.Graphics.DrawImage(bmp, e.MarginBounds)
End Using
Using bmp2 As New Bitmap(Form1.pb2.Width, Form1.pb2.Height)
Form1.pb2.DrawToBitmap(bmp2, New Rectangle(0, 0, Form1.pb2.Width, Form1.pb2.Height))
Dim x as Double = Form1.pb2.Location.X - Form1.pb1.Location.X
x = x * e.MarginBounds.Width / Form1.pb1.Width
x = x + e.MarginBounds.X
Dim y as Double = Form1.pb2.Location.Y - Form1.pb1.Location.Y
y = y * e.MarginBounds.Height / Form1.pb1.Height
y = y + e.MarginBounds.Y
Dim width as Double = Form1.pb2.width
width = width * e.MarginBounds.Width / Form1.pb1.Width
Dim height as Double = Form1.pb2.Height
height = height * e.MarginBounds.Height / Form1.pb1.Height
e.Graphics.DrawImage(bmp2, New Rectangle(x, y, width, height))
End Using
End Sub