Can't print in landscape orientation

  • Thread starter Thread starter egarcia1970
  • Start date Start date
E

egarcia1970

Hi group.

I'm having problems getting this C# code to print in landscape
orientation:

private void MyPrintDocument_BeginPrint(object sender,
System.Drawing.Printing.PrintEventArgs e)
{

MyPrintDocument.PrinterSettings.DefaultPageSettings.Landscape = true;

MyPrintDocument.PrinterSettings.DefaultPageSettings.Margins.Left = 25;

MyPrintDocument.PrinterSettings.DefaultPageSettings.Margins.Right = 25;

MyPrintDocument.PrinterSettings.DefaultPageSettings.Margins.Top = 50;

MyPrintDocument.PrinterSettings.DefaultPageSettings.Margins.Bottom =
50;
}

private void MyPrintDocument_PrintPage(object sender,
System.Drawing.Printing.PrintPageEventArgs e)
{
if (k < MyReportReader.Pages.Count)
{
if (chklstBills.GetItemCheckState(k) ==
CheckState.Checked)
{
e.HasMorePages = true;
Font prFont = new Font("Courier New", 10,
GraphicsUnit.Point);
Page currentPage = (Page)MyReportReader.Pages[k];
int j;

for (j = 0; j < currentPage.Lines.Count; j++)
{
float x, y;
x = 26;
y = 50 + (float)j * (float)12.5;

e.Graphics.DrawString(currentPage.Lines[j].ToString(), prFont,
Brushes.Black, x, y);
}
}
k++;
}
else
{
e.HasMorePages = false;
}
}


ReportReader and Page are custom classes for this application
MyPrintDocument is an instance of the PrintDocument class.
Using .NET framework 2.0

This code prints in portrait orientation in any printer no matter what
I do, ignoring the
'MyPrintDocument.PrinterSettings.DefaultPageSettings.Landscape = true'
statement in the BeginPrint event handler. It's not a printer problem.

Any help will be greatly appreciated.
 
Try setting the landscape property in the OnQueryPageSettings event, like this:

Protected Overrides Sub OnQueryPageSettings(ByVal e As
System.Drawing.Printing.QueryPageSettingsEventArgs)

e.PageSettings.Landscape = True

End Sub

I think that wil solve your problem.

Joris
 
Back
Top