这是我第一次使用打印预览而感到困惑,所以我需要一个建议:
这是我要打印的对话框:
这是我目前在PrintPreview对话框中的显示方式(搞砸了):
这是我目前的完整代码:
Public Class frmPRINT
Private Sub btnPrint_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
PrintDocument1.Print()
End Sub
Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
Dim bm As New Bitmap(DataGridView1.Width, DataGridView1.Height)
DataGridView1.DrawToBitmap(bm, New Rectangle(0, 0, DataGridView1.Width, DataGridView1.Height))
e.Graphics.DrawImage(bm, 0, 0)
End Sub
Private Sub btnPrintPreview_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrintPreview.Click
PrintPreviewDialog1.WindowState = FormWindowState.Normal
PrintPreviewDialog1.StartPosition = FormStartPosition.CenterScreen
PrintPreviewDialog1.ClientSize = New Size(600, 600)
PrintPreviewDialog1.Document = PrintDocument1
PrintPreviewDialog1.ShowDialog()
End Sub
End Class
我该如何正确设置呢?
答案 0 :(得分:2)
使用
将页面方向设置为横向printDocument1.DefaultPageSettings.Landscape = true
有关详细信息,请参阅PrintDocument.DefaultPaperSettings
上的MSDN文档。