vb.net 正确使用 PrintPreview 对话框

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13782735/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 11:29:58  来源:igfitidea点击:

Properly using PrintPreview dialog

vb.netprintingprint-preview

提问by Altin

This is my first time I have to use print preview and I got confused so I need a suggestion:

这是我第一次必须使用打印预览,我很困惑,所以我需要一个建议:

enter image description here

在此处输入图片说明

this is the dialog that I wanna print:

这是我想打印的对话框:

this is how it currently looks in my PrintPreview dialog (messed up): enter image description here

这是它目前在我的 PrintPreview 对话框中的外观(搞砸了): 在此处输入图片说明

this is my full code at the moment:

这是我目前的完整代码:

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

how can I set this up properly please?

我该如何正确设置?

采纳答案by Ken White

Set the page orientation to landscape with

将页面方向设置为横向

printDocument1.DefaultPageSettings.Landscape = true

For more information, see the MSDN documentation on PrintDocument.DefaultPaperSettings.

有关更多信息,请参阅 MSDN 文档PrintDocument.DefaultPaperSettings