Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,
Line having coordinates (0,0) and (1000,1400) would draw the line on these coordinates only, not taking the page margins property of the Page Settings into account,

protected void ThePrintDocument_PrintPage (object sender, System.Drawing.Printing.PrintPageEventArgs ev)
{

//Create PrinterSettings object
PrinterSettings ps = new PrinterSettings();

//Create PageSettings object
PageSettings pgSetting = new PageSettings(ps);

ev.PageSettings.Margins.Left = 50;
ev.PageSettings.Margins.Right = 100;
ev.PageSettings.Margins.Top = 50;
ev.PageSettings.Margins.Bottom = 100;

ev.Graphics.DrawLine(new Pen(Brushes.Violet, 5),
new Point(0, 0),
newPoint(1000, 1400));

}

If i set
ThePrintDocument.OriginAtMargins = true;

then it draws the line from left and top margin but what about the right and bottom margins. The DrawLine method is printing line in right and bottom margins also

I need to set margins on all pages of print document while drawing lines

What I should do for this, please help
Posted
Updated 6-Jun-11 23:59pm
v2

As you've discovered, the coordinate space of the paper includes the margins. Use ev.PageSettings.Margins to determine what the margins are, and adjust your line drawing coordinates appropriately.
 
Share this answer
 
Thanks for the reply,
I am not getting how to draw the line according so that my right and bottom margin are also set,
I think the printable area of the page would be set,
How can I do that??
 
Share this answer
 
Try these things, haven't tried this on a sample, perhaps may help you get around a solution.

// Either you may have to translate the graphics
e.Graphics.TranslateTransform(x, y);

// Or you can limit the clipping region
e.Graphics.Clip = new Region(e.PageSettings.PrintableArea);


Hope this helps!.
 
Share this answer
 
Thanks a lot
I set
e.Graphics.Clip = new Region(e.MarginsBound);
and it worked, but the transformation should be done after setting the clip.
Thanks
 
Share this answer
 

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