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);
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?
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.
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.
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.
Or use a report generator. They exist to solve this problem. Google “.net report generator” to start shopping.