Microsoft KB Archive/817042

= PRB: The PrintDocument Object Prints a Graphical Object with Incorrect Margins =

Article ID: 817042

Article Last Modified on 5/12/2007

-

APPLIES TO


 * Microsoft .NET Framework 1.1
 * Microsoft .NET Framework 1.0
 * Microsoft Windows XP Professional
 * Microsoft Windows XP Professional for Itanium-based systems

-



SYMPTOMS
When you print a graphical object, what appears on the page is shifted away from the position that you expect it to appear in. The distance that the graphical object is shifted depends on the margins that have been set on the printer.

To explain in more detail, when you use the PrintPageEventArgs.Graphics object to print a graphical object on the PrintPage event of the PrintDocument object, PrintDocument ignores the actual physical margins (that is, the printer limitations) of the selected printer. Instead, the printout is shifted according to the margin settings of the printer.



.NET Framework 1.1
To resolve this problem in version 1.1, set the following margin values before you print the document:

PrintDocument1.OriginAtMargins = True



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.



Steps to Reproduce the Behavior
 Start Microsoft Visual Studio .NET. On the File menu, click New, and then click Project. Under Project types, click Visual Basic Projects, and then click Windows Application under Templates. By default, Form1 is created. Add the following controls to Form1 from the Toolbox: Button, PrintPreviewDialog, and PrintDocument. Right-click Form1, and then click View Code.  Paste the following code after the Windows Form Designer generated code: Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage e.Graphics.DrawRectangle(System.Drawing.Pens.Blue, 0, 0, 100, 100) End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Try PrintPreviewDialog1.Document = PrintDocument1 PrintPreviewDialog1.ShowDialog Catch ex As Exception MessageBox.Show(ex.Message) End Try End Sub </li> On the Build menu, click Build Solution.</li> Press F5 to start the application. Form1 appears.</li> Click Button1. The Print preview form appears.</li> Click the Print button.

A blank page with a rectangular border is printed on your selected printer. Notice the margin of the rectangle.</li></ol>

<div class="references_section">

For more information about the PrintDocument class, visit the following MSDN Web site:

http://msdn2.microsoft.com/en-us/library/system.drawing.printing.printdocument.printpage(vs.71).aspx

Keywords: kbdswgdi2003swept kbprb kbwindowsforms kbgdiplus kbgdipprinting kbgdi KB817042

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.