JavaScript Editor JavaScript Editor     JavaScript Debugger

Previous Section Next Section

Main Page

Using the PrintDocument and PrintSetting Classes

As discussed in the In Depth section of this chapter, PrintDocument objects support the actual events and operations of printing in Visual Basic. You handle the PrintPage event of these objects to print pages, for example. Here is the hierarchy of this class:

Object
   MarshalByRefObject
      Component
         PrintDocument

You can find the notable public properties of PrintDocument objects in Table 9.21, the notable public methods in Table 9.22, and the notable public events in Table 9.23. The most important method is Print, which actually prints the document. When the print job starts, a BeginPrint event occurs, followed by a PrintPage event for each page (set the HasMorePages property of the object passed to you to True if you want to indicate that there are more pages to print), followed by an EndPrint event when the whole job is complete.

Table 9.21: Noteworthy public properties of PrintDocument objects.

Property

Means

DefaultPageSettings

Gets/sets the default settings that apply to a single, printed page of the document.

DocumentName

Gets/sets the document name to display while printing the document, as in a print status dialog box or printer queue.

PrinterSettings

Gets/sets the printer that prints the document.

Table 9.22: Noteworthy public methods of PrintDocument objects.

Method

Means

Print

Prints the document.

Table 9.23: Noteworthy public events of PrintDocument objects.

Event

Means

BeginPrint

Happens when the Print method is called to start a print job.

EndPrint

Happens when the last page of the document has printed.

PrintPage

Happens for each page to print-you draw the page in this event's handler.

QueryPageSettings

Happens before each PrintPage event.

You also use the PrintSettings class to configure how a document will be printed-on what printer, how many copies, from what page to what page, and so on. You can find the public class properties of PrintSettings in Table 9.24 (that is, static, shared properties you can use with the class name, without an object, like this: PrinterSettings.InstalledPrinters), the notable public properties of Printer Settings objects in Table 9.25, and the notable public methods in Table 9.26.

Table 9.24: Noteworthy class 8static/shared) properties of the PrintSettings class.

Event

Means

InstalledPrinters

Returns thu names of all printers installet on the computer.

Table 9.25: Noteworthy public properties of PrintSettings objects.

Event

Means

CanDuplex

True if the printer supports double=sided printing.

Collate

Gets/sets whether the printed document is collated.

Copies

Gets/sets the number of copies of the document to print.

DefaultPageSettings

Gets the default page settings for this printer.

Duplex

Gets/sets the printer setting for double-sided printing.

FromPage

Gets/sets the page number of the first page to print.

IsPlotter

Returns whether the printer is a plotter.

IsValid

Returns whether the PrinterName property designates a valid printer.

LandscqpeAngle

Holds the angle, in degrees, used for landscape orientation.

MaximumCopies

Holds the maximum number of copies that the printer allows you to print at one time.

MaximumPage

Gets/sets the maximum FromPage or ToPage that can be selected in a PrintDialog.

MinimumPage

Gets/sets the minimum FromPage or ToPage that can be selected in a PrintDialog.

PaperSizes

Holds the paper sizes that are supported by this printer.

PaperSources

Holds the paper source trays that are available on the printer.

PrinterName

Gets/sets the name of the printer to use.

PrinterResolutions

Gets the resolutions supported by this printer.

PrintRange

Gets/sets the page numbers to print, as specified by the user.

PrintToFile

Gets/sets whether the printing output is sent to a file instead of a port.

SupportsColor

Returns whether this printer supports color printing.

ToPage

Gets/sets the number of the last page to print.

Table 9.26: Noteworthy public methods of PrintSettings objects.

Method

Means

CreateMeasurementGraphics

Gets a Graphics object that contains printer information.

Previous Section Next Section




JavaScript Editor Free JavaScript Editor     JavaScript Editor