本文介绍了如何在使用DrawLine()打印各种线条时设置边距的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,
坐标为(0,0)和(1000,1400)的线只会在这些坐标上绘制线,而不考虑页面设置的页面边距属性,

受保护的void ThePrintDocument_PrintPage(对象发送者,System.Drawing.Printing.PrintPageEventArgs ev)
{

//创建PrinterSettings对象
PrinterSettings ps =新的PrinterSettings();

//创建PageSettings对象
PageSettings pgSetting =新的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(新Pen(Brushes.Violet,5),
新Point(0,0),
newPoint(1000,1400));

}

如果我设置
ThePrintDocument.OriginAtMargins = true;

然后从左边界和上边界画一条线,而右边界和下边界呢? DrawLine方法是在右侧和底部页边距中打印线条

在绘制线条时,我需要在打印文档的所有页面上设置页边距

我应该怎么做,请帮助

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

推荐答案



// 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!.


这篇关于如何在使用DrawLine()打印各种线条时设置边距的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-19 07:46