Programs | printing | Control I have described in a previous article how to capture the output from a console command and put it on the Clipboard. I often need to print out the text output from some console commands, so I modified the last example to support printing.
. NET Print framework is not unfamiliar to people who use MFC: You just have to create a PrintDocument object and call its print () method. The PrintDocument object will call the event processing you create to print each page. After all the pages have been printed, the print process sets a tag and ends printing.
In this new example, I made three changes in the area. First, I modified the storage method (storage) to save the captured input in a ArrayList, and each row entered becomes a string in the collection: private void Grabstream (TextReader instream)
{
String str;
while (null!= (str = instream.readline ()))
{
Listostrings.add (str);
Pipe it to the output:
System.Console.WriteLine (str);
}
}
Next, I added some command-line options to enable it to send data to the Clipboard or the default printer, or both.
Finally, I wrote two programs to print out the output Printdata () method to create a PrintDocument object and start the printing process. It is also responsible for adding an event handler for the Print page processing.
The PrintPage () method is used to print each page. First, I calculated the number of lines that fit the printed page. The GetHeight () method of the font displays the height of a single row, and the Printpageevent MarginBounds property shows how large the print space is for each page. With this information, I can simply draw the header line, each row of the page, and the footer row.
There is a small problem with the print frame: The PageBounds property represents the size of the entire page, not the size of the printable area. I tried to qualify headers and footers outside the print area, but it didn't work. On some printers, the areas below the print area cannot be printed. So I can simply adjust the margins and place the headers and footers in the print area.
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