Printer and Page Properties

Team Fly 

Page 162

NOTE You can use the SetClip method of the Graphics object that represents the page to impose the margins. This method prohibits printing outside a specified rectangle, and you can use it to make sure that all graphics elements that fall outside this rectangle are clipped. In most cases, however, we write code to arrange the graphic elements on the page taking into consideration the margins. When we print text, for example, we write code to break the lines when the text reaches the right margin, or start a new page when the text reaches the bottom of the page.

When the event handler exits, the appropriate graphics commands are sent to the printer and the page is actually printed. If you need to print additional pages, you set the e.HasMorePages property to True just before you exit the event handler. This will fire another PrintPage event. The same process will repeat until all the pages have been printed. When you're finished, you set the e.HasMorePages property to False, and no more PrintPage events will be fired. The default value of this property is False, so you need not set it when you're done printing.

Printer and Page Properties

One of the most common tasks in writing code to generate printouts is to retrieve the settings of the current printer and page, as they were specified by the user on the PageSetup and PrinterSetup dialog boxes. The properties specified on these two dialog boxes are reported to your application through the PrinterSettings and PageSettings objects. The PageSettings object is a property of the PrintPageEventArgs class, and you can access it through the e argument of the PrintPage event handler. The DefaultPageSettings property of the PrintDocument object is also a PageSettings object.

The PrinterSettings object is a property of the PrintDocument object, as well as a property of the PageSetupDialog and PrintDialog controls. Finally, one of the properties exposed by the PageSettings object is the PrinterSettings object. These two objects provide all the information you may need about the selected printer and the current page through the properties listed next.

The PageSettings Object

The PageSettings object exposes the following properties, which you can use to retrieve the properties of the current page.

Bounds Returns a Rectangle object that represents the current page. Its dimensions are expressed in hundredths of an inch. The PageSettings.Bounds property is equivalent to the MarginBounds property of the e argument of the PrintPage event handler. The Bounds property doesn't take into consideration the margins specified by the user on the PageSetup dialog. For a letter-size page the dimensions of this rectangle are 850×1100, and for an A4 page they are 827×1169.

Color Returns a True/False value indicating whether the current page can print in color. You can set this property to determine whether the page should be printed in color or not.

Landscape Returns a True/False value indicating whether the page should be printed in landscape or portrait orientation. Use this property to find out the orientation specified by the user on the PageSetup dialog; setting this property won't affect the printout, because you still have to provide the appropriate code to print in landscape orientation (i.e., swap the page's width and height).

Margins Returns a Margins object, which exposes the user-specified margins as properties (Top, Left, Right, and Bottom). The properties of the Margins object are expressed in hundredths of an inch.

Team Fly 


Visual Basic  .NET Power Tools
Visual Basic .NET Power Tools
ISBN: 0782142427
EAN: 2147483647
Year: 2003
Pages: 178

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net