即使设置了值,打印范围也不起作用

编程入门 行业动态 更新时间:2024-10-09 09:20:11
本文介绍了即使设置了值,打印范围也不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我设置了一个简单的打印解决方案,并且正常打印可以正常工作(测试了几次),但是当我使用PrintDialog指定自定义页面范围时,就好像该范围已过.调试时,我检查printDocument对象并确认范围值正确,但是打印机产生的最终产品与我给它的值相差不大.

I have a simple printing solution set up and normal printing works fine(tested it a couple of times), however when I use the PrintDialog to specify a custom page range, it is as if the range is ingored. When I debug I inspect the printDocument object and confirm that the range values are correct but the end product that the printer produces does not much the values I gave it.

这是我的代码:

printDialog.Document = printdoc; printDialog.AllowSomePages = true; if (printDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { printdoc.PrinterSettings.FromPage = printDialog.PrinterSettings.FromPage; printdoc.PrinterSettings.ToPage = printDialog.PrinterSettings.ToPage; printdoc.PrinterSettings.PrintRange = printDialog.PrinterSettings.PrintRange; printPreviewDialog.Document = printdoc; printPreviewDialog.FindForm().WindowState = FormWindowState.Maximized; printPreviewDialog.ShowDialog(); }

*注意-printdoc是System.Drawing.Printing.PrintDocument的实例.我在PrintDocument的PrintPage事件处理程序中添加了代码,以填充我正在打印的页面.

*Note - printdoc is a instance of System.Drawing.Printing.PrintDocument. I added code in the PrintDocument's PrintPage event handler to populate the page I'm printing.

推荐答案

您需要告诉打印对话框它应该接受用户输入的页面范围.为此,您可以指定 PrinterSettings.PrintRange .

You need to tell the print dialog that it should accept user input for page ranges. To do this, you can specify the PrinterSettings.PrintRange.

var printDialog = new PrintDialog(); printDialog.AllowSomePages = true; //May not be needed printDialog.PrinterSettings.PrintRange = PrintRange.SomePages; //Needed if(printDialog.ShowDialog() == DialogResult.OK) { // ... do the rest here }

注意:您应该得到的主要建议是,需要设置PrintDialog.AllowSomePages = true(以及From/ToPage),以便告诉对话框仅打印这些范围.另外,我不确定在对话框关闭后设置AllowSomePages是否会生效,所以这就是为什么我将代码放在ShowDialog之前的原因.您可以尝试在方便时在if语句中设置它.

Notes: The main takeaway you should get is that you need to set PrintDialog.AllowSomePages = true (along with From/ToPage) in order to tell the dialog to only print those ranges. Also, I am not sure if setting the AllowSomePages after the dialog closes will take effect, so that's why I put the code before ShowDialog. You can try to set it inside the if-statement at your convenience.

更多推荐

即使设置了值,打印范围也不起作用

本文发布于:2023-10-26 06:51:25,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1529395.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:也不

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!