如何使用c#,windows窗体将面板控件打印为纵向和横向 [英] How to print panel control as portrait and landscape using c#, windows forms

查看:223
本文介绍了如何使用c#,windows窗体将面板控件打印为纵向和横向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将面板控制打印为纵向和横向,因为我从后端加载打印设置,因此它将影响打印。

解决方案

这是一个想法:你可以知道它,但你真的不需要从风景中分辨出肖像。您只需要知道纸张尺寸,您将始终从页面信息中了解纸张尺寸。无论如何你需要知道尺寸,才能正确渲染打印图形。



使用类

https://msdn.microsoft.com/en-us/library/system.drawing.printing.printdocument%28v=vs.110%29.aspx [ ^ ]。



现在,请查看代码示例并注意如何处理事件 PrintPage 。首先,将 PrintPageEventArgs 的实例传递给您的处理程序。看看这种类型:

https://msdn.microsoft.com/en-us/library/system.drawing.printing.printpageeventargs%28v=vs.110%29.aspx [ ^ ]。



如您所见,事件参数包括 MarginBounds PageBounds <等数据/ code>。您可以使用此布局信息直接构建打印时呈现的数据的布局。但是如果你愿意,你仍然可以获得属性 PrintPageEventArgs.PageSettings 。从这个属性,你知道这是肖像还是风景:

https://msdn.microsoft.com/en-us/library/system.drawing.printing.printpageeventargs.pagesettings%28v=vs.110%29 .aspx [ ^ ],

https://msdn.microsoft.com/en-us/library/system.drawing.printing.pagesettings%28v=vs.110%29.aspx [ ^ ]。



就是这样。



- SA

Print panel control as portrait and landscape because I am loading print setting from back end so it will effect in to the printing.

解决方案

Here is the idea: you can know it, but you don't really need to tell "portrait" from "landscape". You only need to know the paper size, which you will always know from the page information. You need to know the size anyway, to render the printing graphics correctly.

You do all printing using the class :
https://msdn.microsoft.com/en-us/library/system.drawing.printing.printdocument%28v=vs.110%29.aspx[^].

Now, please look at the code sample and pay attention how the event PrintPage is handled. First of all, the instance of PrintPageEventArgs is passed to your handler. Look at this type:
https://msdn.microsoft.com/en-us/library/system.drawing.printing.printpageeventargs%28v=vs.110%29.aspx[^].

As you can see, the event arguments include such data as MarginBounds and PageBounds. You can use this layout information to directly build the layout for the data rendered on print. But if you want, you still get the property PrintPageEventArgs.PageSettings. From this property, you know if this is "portrait" or "landscape":
https://msdn.microsoft.com/en-us/library/system.drawing.printing.printpageeventargs.pagesettings%28v=vs.110%29.aspx[^],
https://msdn.microsoft.com/en-us/library/system.drawing.printing.pagesettings%28v=vs.110%29.aspx[^].

That's all.

—SA


这篇关于如何使用c#,windows窗体将面板控件打印为纵向和横向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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