以横向模式打印 vb.net

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

Printing in Landscape mode vb.net

vb.net

提问by Ronnie Adriane Baetiong

i had manage to print the contents of my datagrid view, but it doesnt fit in portrait mode. i guess printing it in landscape mode will do.

我设法打印了我的数据网格视图的内容,但它不适合纵向模式。我想以横向模式打印它就可以了。

i have this code for my dataset to fill the datagridview.

我有这个代码用于我的数据集来填充 datagridview。

Private Sub print_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    Dim query As String = "SELECT * FROM TBLusers"
    Dim DA As New SqlDataAdapter(query, CN)
    Dim DS As New DataSet
    CN.Open()

    DA.Fill(DS, "Users")
    CN.Close()
    DataGridView1.DataSource = DS.Tables("Users")
    'DataGridView1.DataMember = "Users"


End Sub

here is the function for printing i guess? i got it from a tutorial.

我猜这是打印功能?我从教程中得到的。

Private Sub printDocument1_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage

    Dim dataGridViewImage As New Bitmap(Me.DataGridView1.Width, Me.DataGridView1.Height)
    DataGridView1.DrawToBitmap(dataGridViewImage, New Rectangle(0, 0, Me.DataGridView1.Width, Me.DataGridView1.Height))
    e.Graphics.DrawImage(dataGridViewImage, 0, 0)
End Sub

here is the print preview.

这是打印预览。

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

    PrintPreviewDialog2.Document = PrintDocument1
    PrintPreviewDialog2.PrintPreviewControl.Zoom = 1
    PrintPreviewDialog2.ShowDialog()
End Sub

and the print...

和打印...

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    PrintDocument1.Print()
End Sub

i tried
PrintDocument1.PrinterSettings.DefaultPageSettings.Landscape = True

我试过
PrintDocument1.PrinterSettings.DefaultPageSettings.Landscape = True

but it doesnt seems to work?

但它似乎不起作用?

回答by Robin V.

You're setting the DefaultPagesetting for the printer. Try to set it for the document itself:

您正在设置DefaultPage打印机的设置。尝试为文档本身设置它:

PrintDocument1.DefaultPageSettings.Landscape = True
PrintDocument1.Print()