About

I am a software developer in Seattle, building a new AI software company.

Ads

May 2008

Sun Mon Tue Wed Thu Fri Sat
        1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31

Ads


« Technology Is Young | Main | Microsoft's Giving Away Its Most Prized Tools »

May 26, 2004

Easier Printing in Whidbey

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).

Comments

It's good they didn't cop out and shove it into "My.Printer.Document"

This class is gone. :-(

The comments to this entry are closed.