如何在使用DrawLine()打印各种线条时设置边距 [英] How to set margins while printing various lines using DrawLine()

查看:110
本文介绍了如何在使用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

推荐答案

如您所见,纸张的坐标空间包括边距.使用ev.PageSettings.Margins确定边距是多少,并适当调整线条画坐标.
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.


感谢您的答复,
我没有得到如何根据这条线来画线,这样我的右边距和底边距也被设置了,
我认为将设置页面的可打印区域,
我该怎么做??
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??


尝试这些事情,还没有在示例中尝试过,也许可以帮助您解决问题.

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


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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆