Set print orientation to landscape

35,009

try setting the Landscape of PrintDocument as follows,

printDocument1.DefaultPageSettings.Landscape = true;
Share:
35,009
Kaoru
Author by

Kaoru

Updated on July 10, 2022

Comments

  • Kaoru
    Kaoru almost 2 years

    i already can create a print to print a file in my windows forms. However, whenever i add this code:

    printDialog.PrinterSettings.DefaultPageSettings.Landscape = true;
    

    I can't see the Orientation of the page become LandScape, it is still Portrait.

    How do I make it LandScape as default? So, whenever i click PrintPreview or PrintFile, the Orientation of the page will become LandScape, not Portrait.

    Here is the code:

    private void PrintPreview(object sender, EventArgs e)
    {
        PrintPreviewDialog _PrintPreview = new PrintPreviewDialog();
        _PrintPreview.Document = printDocument1;
        ((Form)_PrintPreview).WindowState = FormWindowState.Maximized;
        _PrintPreview.ShowDialog();
    }
    
    private void PrintFile(object sender, EventArgs e)
    {
        PrintDialog printDialog = new PrintDialog();
        printDialog.Document = printDocument1;
        printDialog.UseEXDialog = true;
    
        if (DialogResult.OK == printDialog.ShowDialog())
        {
            printDocument1.DocumentName = "Test Page Print";
            printDocument1.Print();
        }
    }
    
    • Robert Levy
      Robert Levy over 10 years
      are you adding that line before calling ShowDialog()?
    • Kaoru
      Kaoru over 10 years
      yes, i added that line right before call the ShowDialog();, though i called it in PrintFile function
  • Kaoru
    Kaoru over 10 years
    and, what is the page sir?
  • dev1998
    dev1998 about 5 years
    This is good. Be advised that printDocument1.PrinterSettings.DefaultPageSettings.Landscape = true; did not work. Make sure you have just like the answer and not with PrinterSettings.