问题描述
我需要System.Drawing.Printing.PaperKind得到纸张大小。是否有任何预定义的值?我不想硬编码或计算的纸张尺寸,我只是想获得它编程。谢谢你。
I need to get paper size by System.Drawing.Printing.PaperKind. Are there any predefined values? I don't want to hardcode or calculate paper sizes, I just want to get it programmatically. Thanks.
推荐答案
预设值的子集可以通过遍历一个 PrinterSettings.PaperSizes 有code>集合。
A subset of predefined values can be had by iterating over a PrinterSettings.PaperSizes
collection.
我们的应用程序,用户选择一台打印机,为我们提供了一个的对象。在 PrinterSettings
包含为打印机支持 PAPERSIZE
的列表 - 不是万能的(注意,XPS文档驱动程序(WIN7)支持所有规格)。
Our application has the user select a printer, providing us with a PrinterSettings
object. Contained within PrinterSettings
is a list of PaperSize
's supported by the printer - not everything (note that the XPS Document Driver (win7) supports all sizes).
在我们的例子中支持的尺寸的这个子集是我们所需要的。指定的用户 PaperKind
传递给我们的打印代码,并经过我们的 PrinterSettings
对象直至找到用户选择或放弃,并使用默认值。
In our case this subset of supported sizes is all we need. A user specified PaperKind
is passed to our printing code, and it goes through our PrinterSettings
object until it either finds the user's selection or gives up and uses a default.
在下面的例子中,你可以看到 PAPERSIZE
对象是正确的。填写
In the example below you can see that the PaperSize
objects are correctly filled.
PrinterSettings settings = new PrinterSettings();
foreach (PaperSize size in settings.PaperSizes)
Debug.WriteLine(size);
这只是一个子集,但也许这也够你。在.NET中印API是真的不清楚,MSDN是不是真的有很大帮助......希望它让你在正确的轨道上!
It's only a subset, but maybe that's also enough for you. the printing APIs in .NET are really unclear and msdn isn't really much help... Hopefully it puts you on the right track!
这篇关于如何通过PaperKind获得预定的纸张尺寸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!