Home > DeveloperSection > Forums > Printing in Landscape mode vb.net
ben reitman
ben reitman

Total Post:96

Posted on    October-05-2013 2:47 AM

 VB.Net VB.Net 

 1 Reply(s)
 7614  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?

F Scott Fitzgerald
F Scott Fitzgerald

Total Post:29

Posted on    October-05-2013 4:24 AM

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

PrintDocument1.DefaultPageSettings.Landscape = True

Don't want to miss updates? Please click the below button!

Follow MindStick