Easier Printing in Whidbey

5/26/2004 7:58:09 AM

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();

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






Net Undocumented is a blog about the internals of .NET including Xamarin implementations. Other topics include managed and web languages (C#, C++, Javascript), computer science theory, software engineering and software entrepreneurship.

Social Media