Click here to Skip to main content
15,887,862 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to print a rectangle in inside of a A4 paper.
When i say inside the paper i mean in boundary of Page Margins. There are three controls on my form.
C#
PrintDocument, PageSetupDialog, PrintPreviewDialog


And code for PrintPage event of the PrintDocument.

private void printDocument_PrintPage(object sender, PrintPageEventArgs e)
{
Graphics gr = e.Graphics;
Rectangle r = e.MarginBounds;

Pen pen = new Pen(Brushes.Black, 1.0F);
gr.DrawRectangle(pen, r.Left,r.Top,r.Right,r.Bottom);
}
But the result is not what i expected.
The rectangle is shifted to the right.
Where is the right side of the rectangle?
Why it shifted to the right?
How can i draw into real PageMargins?
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900