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.