C # how to hide the print window during printing

Source: Internet
Author: User

Recently, we have been developing a release package management software. On the interface, we have a bunch of text boxes and other controls for input. When a user inputs a piece of data, press enter to automatically jump to the next text box, if it is the last text box, it indicates that the input is complete and the ticket is printed immediately. To simplify user input, each text box usually has a default value. Therefore, you can press enter in most cases, after being proficient, I usually only need to modify a small amount of data, and then press enter all the way to complete the input of a list, very happy, I use the PrintDocument class for printing, when using PrintDocument. print (), a "printing, number? Page, total? Page to remind users that there is only one "cancel" button in the window. It seems that Microsoft is very user-friendly and thoughtful, however, the humanization of Microsoft has brought me unexpected troubles. As mentioned above, users usually press enter all the way. When the print window appears, there is only one cancel button on it, the user pressed the carriage return button. When the window appears, the user Press enter. The print is canceled. How can he not display the window? After searching for the window for a long time, there is no answer, now we have solved the problem. Use the following code before print:

1. Define a PrintDocument class:

System. Drawing. Printing. PrintDocument prnDocument = new System. Drawing. Printing. PrintDocument ();

2. Do the following before print:

PrnDocument. PrintController = new System. Drawing. Printing. StandardPrintController ();

3. Perform other operations.

That is, the second step above is added to the Common Code. Then, you will find that there is no annoying Print dialog box. At this point, the problem is solved.

In addition, I found that printing should be placed in a separate thread to Implement Asynchronous printing. Otherwise, errors may occur when the number of printed tickets is too large.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.