---
title: "Printing in Landscape mode vb.net"  
description: "Printing in Landscape mode vb.net"  
author: "Anonymous User"  
published: 2013-10-05  
updated: 2023-07-06  
canonical: https://www.mindstick.com/forum/1597/printing-in-landscape-mode-vb-dot-net  
category: "vb.net"  
tags: ["vb.net"]  
reading_time: 3 minutes  

---

# Printing in Landscape mode vb.net

i had manage to [print](https://www.mindstick.com/blog/301752/types-of-3d-printing-technology) the contents of my datagrid [view](https://yourviews.mindstick.com/view/84701/layoffs-in-google-india-2023-view), but it doesnt fit in portrait mode. i guess [printing](https://www.mindstick.com/blog/63804/5-ways-you-can-use-printing-in-your-marketing-strategy) it in [landscape mode](https://www.mindstick.com/forum/23288/orientation-issue-how-to-disable-landscape-mode-in-android) will do.

**i have this [code](https://yourviews.mindstick.com/view/85458/alan-turing-the-mastermind-behind-cracking-the-enigma-code-during-world-war-ii) for my [dataset](https://www.mindstick.com/articles/19/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](https://www.mindstick.com/articles/13001/multi-statement-table-valued-user-defined-function-in-sql-server) 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](https://yourviews.mindstick.com/view/81326/boycott-chinese-products-dream-will-come-true)

\

but it doesnt seems to work?

## Replies

### Reply by Aryan Kumar

Sure, I can help you with that. Here are the steps on how to print in landscape [mode](https://yourviews.mindstick.com/view/81372/us-congress-should-go-in-remote-mode-for-proper-functioning) in VB.NET:

1. Import the `System.Drawing` namespace.
2. Get the PageSettings object from the `PrintDocument` object.
3. Set the `Landscape` property of the PageSettings object to `True`.
4. Print the document.

Here is an example of how to print in landscape mode in VB.NET:

VB.Net

```plaintext
Imports System.Drawing

Sub Main()
    ' Create a new PrintDocument object.
    Dim printDocument As New PrintDocument()

    ' Get the PageSettings object from the PrintDocument object.
    Dim pageSettings As PageSettings = printDocument.PageSettings

    ' Set the Landscape property of the PageSettings object to True.
    pageSettings.Landscape = True

    ' Print the document.
    printDocument.Print()
End Sub
```

This code will create a new PrintDocument object and set the PageSettings object to landscape mode. The code will then print the document.

Here is an explanation of the code:

- The `PrintDocument` class represents a PrintDocument object.
- The `PageSettings` class represents the page settings for a PrintDocument object.
- The `Landscape` property of the `PageSettings` class specifies whether the document should be printed in landscape mode.
- The `Print` method of the `PrintDocument` class prints the document.

### Reply by Anonymous User

You're setting the **DefaultPage** setting for the printer. Try to set it for the document

\

itself:

\

\

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

\


---

Original Source: https://www.mindstick.com/forum/1597/printing-in-landscape-mode-vb-dot-net

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
