以高质量打印 winform? [英] Print the winform in high quality?
问题描述
我是编写代码的新手,但正在学习 C# 并且正在为我的商店制作一个小账单制作程序.我需要打印表格,这是我的帐单.从网上搜索,我找到了这段代码:
I am new to writing code, but am learning C# and am making a little bill-making program for my shop. I need to print the form, which is my bill. From searching on the internet, I found this piece of code:
printForm1.Print(this, PrintForm.PrintOption.ClientAreaOnly);
我的帐单有两张图片和一张 gridviewbox
.此代码可以打印账单,但 .xps 文件的质量很差 - 甚至文本打印不清晰.
My billing form has two images and one gridviewbox
. This code can print the bill, but quality of the .xps file is poor - even the text is not printing sharp.
如何提高表单的打印质量?
How can I increase the print quality of the form?
推荐答案
是的,除非你的手臂很长,否则这看起来不太好.问题是打印机的像素分辨率比显示器高得多.一台像样的打印机具有 600 dpi(每英寸点数)的分辨率.显示器默认为 96 dpi,尽管在坚持了几十年之后终于有所改善.
Yes, that doesn't look good unless you have really long arms. The issue is that printers have a much higher pixel resolution than monitors. A decent printer has a 600 dpi (dots per inch) resolution. Monitors by default are 96 dpi although that's finally improving after being stuck on that for decades.
因此,要按照您的方式打印表单,您有两个令人不快的选择.您可以打印表格,使屏幕上的一个像素相当于纸上的一个像素.这为您提供了原始表格的非常清晰的图像,但它的大小与邮票差不多.或者您在纸上打印出与屏幕上一样大的表格,您现在看到的情况.这会将显示器上的单个像素变成纸上的 6 x 6 斑点.结果看起来很粗糙,尤其是文字看起来很糟糕.
So to print a form the way you do, you have two unpleasant choices. You can print the form so that one pixel on the screen is one pixel on paper. That gives you a really sharp image of the original form but it is about the size of a postage stamp. Or you print the form as big on paper as it is on the screen, what you see happening now. That turns a single pixel on the monitor into a 6 x 6 blob on paper. The result looks very grainy, particularly text looks poorly.
一个解决方案是在屏幕上绘制 6 倍大的表单并打印出来.但是这不起作用,您不能使表单大于屏幕.唯一真正的解决方案是将 6 倍大的打印机绘制到打印机上.这需要 PrintDocument 类.并在其 PrintPage 事件处理程序中编写了一堆代码来进行绘图.您无法哄骗控件为您完成这项工作,因此这是一项繁重的工作.
A solution would be to draw the form 6 times larger on the screen and print that. That however doesn't work, you can't make the form bigger than the screen. The only real solution is to draw 6 times larger to the printer. That requires the PrintDocument class. And a bunch of code in its PrintPage event handler to do the drawing. You can't coax the controls to do it for you so that's a bunch of work.
或者使用报告生成器.他们的存在就是为了解决这个问题.谷歌.net 报告生成器"开始购物.
Or use a report generator. They exist to solve this problem. Google ".net report generator" to start shopping.
这篇关于以高质量打印 winform?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!