Advertise with us

Printing in Landscape mode

Posted by  ben reitman
 9752  View(s)
Rate this:

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.

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
    DA.Fill(DS, "Users")
    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
End Sub

and the print...

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

End Sub

i tried

PrintDocument1.PrinterSettings.DefaultPageSettings.Landscape = True

but it doesnt seems to work?

  1. Re: Printing in Landscape mode

    You're setting the DefaultPage setting for the printer. Try to set it for the document


    PrintDocument1.DefaultPageSettings.Landscape = True

      Modified On Mar-31-2018 05:16:09 AM