Printing in Landscape mode vb.net

Total Post:96

Points:676
VB.Net 
 8958  View(s)
Ratings:
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
    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


but it doesnt seems to work?

  1. Post:28

    Points:196
    Re: Printing in Landscape mode vb.net

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


    itself:



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


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

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!