我正在尝试打印一个窗体。当表单最大化时,图像在页面上运行。我可以在打印之前使用Me.WindowState = FormWindowState.Normal,但我知道这不是最好的方法。是否有更好的“适合页面”的方法,因为用户可以更改表单大小?
Private Sub PrintToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles PrintToolStripMenuItem.Click
Dim ppd As PrintPreviewDialog = New PrintPreviewDialog()
ppd.Document = New Printing.PrintDocument()
AddHandler ppd.Document.PrintPage, AddressOf Document_PrintPage
ppd.Document.DefaultPageSettings.Landscape = True
ppd.ShowDialog()
End Sub
Private Sub Document_PrintPage(ByVal sender As Object, ByVal e As Printing.PrintPageEventArgs)
Dim bt As Bitmap = New Bitmap(Me.Width, Me.Height)
Me.DrawToBitmap(bt, New Rectangle(0, 0, Me.Width, Me.Height))
e.Graphics.DrawImage(bt, 0, 0)
End Sub
答案 0 :(得分:0)
如果有人遇到同样的问题,这似乎会更好。
e.Graphics.DrawImage(bt, 0, 0, e.PageBounds.Width, e.PageBounds.Height)