Whidbey provides simplified printing support via the SimplePrintDocument class in the System.Windows.Forms.Printing namespace.
For example, printing a line of text is almost as simple as utilizing the Console method:
SimplePrintDocument doc = new SimplePrintDocument(); doc.WriteLine(text);
There's also doc.Write(text), doc.WriteTextFile(fileName) and doc.WriteLine() for a simple blank line. Writing a horizontal line is accomplished with WriteHorizontalLine(thickness), an image with WriteImage(Image), and a table with TableBegin() and TableEnd().
The various WriteXXX methods advance the printer position (given by CurrentX and CurrentY properties ) vertically across the page, and automatically starts a new page at the end of the current page. A new page can also be started by calling NewPage().
To change the current color, font, margin and other attributes, SimplePrintDocument offers a number of properties such as BackColor, Color, Font, IndentLeft, IndentRight, and HorizontalAlignment, to name a few. There's also support for absolutely positioned graphics, with DrawXXX and DrawFilledXXX (where XXX is Ellipse, Rectangle, Line, Image, Text, Arc, Circle or Square)
Actual printing is invoked by calling doc.Print(showPrintDialog), doc.PrintPreview, or doc.PrintToFile(fileName).
It's good they didn't cop out and shove it into "My.Printer.Document"
Posted by: Ken Brubaker | May 27, 2004 at 07:02 AM
This class is gone. :-(
Posted by: Klaus Löffelmann | January 19, 2005 at 03:39 PM