Megosztás a következőn keresztül:


Printer Object for Visual Basic 6.0 Users

The Visual Basic 6.0 Printer object is replaced by the PrintDocument component in Visual Basic 2008. The behavior of the two is considerably different, but in most cases the functionality can be duplicated.

Conceptual Differences

In Visual Basic 6.0, printing is accomplished by creating a Printer object and using graphics methods to draw text and graphics onto a virtual page. Properties and methods are used to define printer attributes such as DeviceName, PrintQuality or Copies; other properties such as Orientation and PaperSize define attributes of the page itself. The EndDoc method sends the output to the default printer for the application as defined in the Printers collection.

In Visual Basic 2008, the Printer object no longer exists. Instead, you use a PrintDocument component to define the graphics and text, a PrinterSettings object to define printer attributes, and a PageSettings class to define page attributes.

Note

Visual Basic 2008 has a Printer object that allows upgraded Visual Basic 6.0 Printer code to run without modification. For any new development, you should use PrintDocument.

Printing is no longer tied to a specific device, and the concept of a default printer for an application is no longer valid. Instead the PrintPage method of the PrintDocument component can be used to print to any device, and the default printer is system-wide. The PrintDialog, PrintPreviewDialog, and PageSetupDialog components allow you to let the user select a printer and print options at run time.

ColorMode Property

In Visual Basic 6.0, the ColorMode property controls whether output is printed in monochrome on a color printer.

In Visual Basic 2008, it is now up to the printer to expose this as an advanced option. The SupportsColor property of the PrinterSettings class can be used to determine the color capabilities of a printer.

DriverName Property

In Visual Basic 6.0, the DriverName property of the Printer object is used to specify a printer driver. In early versions of Windows, and in MS-DOS, printer drivers were necessary to translate output in a way that each specific brand and model of printer could understand. By the time of Visual Basic 6.0, this was largely unnecessary, but the property was maintained for backward compatibility.

In Visual Basic 2008, the DriverName property no longer exists; printer drivers are managed by Windows, and you can no longer specify different drivers.

hDC property

In Visual Basic 6.0, the hDC property of the Printer object specifies a handle to a device context (a link between a Windows-based application, a device driver, and an output device, such as a printer).

In Visual Basic 2008, the hDC property no longer exists; an instance of a PrintDocument component is the equivalent of a device context.

Note

Although handles to device contexts are no longer necessary, graphics objects have GetHdc and ReleaseHdc methods that can be used in advanced scenarios.

Page Property

In Visual Basic 6.0, the Page property returns a count of pages that have been printed since your application started or since the last time the EndDoc statement was used on the Printer object. This property is often used to add a page number to each page during printing.

In Visual Basic 2008, page numbers are not tracked; however, you can easily keep a count by setting a variable in the BeginPrint event and incrementing it in the PrintPage event.

Port Property

In Visual Basic 6.0, the Port property returns the name of the port through which a document is sent to a printer.

In Visual Basic 2008, the Port property no longer exists; the PrintDialog and PrintPreviewDialog controls automatically manage port information.

RightToLeft Property

In Visual Basic 6.0, the RightToLeft property determines how the Printer object will format output on a bi-directional platform, such as Arabic Windows 95 or Hebrew Windows 95.

In Visual Basic 2008, the RightToLeft property is no longer necessary; the direction of printing is controlled by the localization settings in later versions of Windows.

TrackDefault Property

In Visual Basic 6.0, the TrackDefault property determines whether a Printer object always points to the same printer, or whether it changes the printer it points to if you change the default printer setting in the operating system's Control Panel. Changing the TrackDefault property setting while a print job is in progress causes printing to halt immediately.

In Visual Basic 2008, the TrackDefault property no longer exists; the IsDefaultPrinter property of the PrinterSettings class can be used to determine if a printer is the default, but printing is no longer halted if the default printer changes.

Zoom Property

In Visual Basic 6.0, the Zoom property determines the percentage by which printed output is to be scaled up or down. For example, consider a letter-sized page printed with Zoom set to 50. This page contains as much data as a page of the size 17 by 22 inches because the printed text and graphics on the letter-sized page are scaled to one-half their original height and width.

In Visual Basic 2008, the Zoom property no longer exists; if a printer has zoom capabilities, settings are automatically exposed in the Print dialog box. You can also use graphics methods to scale the output prior to assigning it to a PrintDocument component.

Graphics Properties and Methods

In Visual Basic 6.0, various graphics properties and methods can be used to draw lines, shapes, and text on a Printer object.

In Visual Basic 2008, most objects no longer have their own graphics properties or methods; you can still draw lines, shapes, and text by creating and using a Graphics object. For more information, see Graphics for Visual Basic 6.0 Users.

Code Changes for the Printer Object

Due to the considerable differences in printing models between Visual Basic 6.0 and Visual Basic 2008, a comparison of the coding techniques is of little value. For an example of printing in Visual Basic 2008, see Printing Sample.

Printer Object Property and Method Equivalencies

The following tables list Visual Basic 6.0 properties and methods, along with their Visual Basic 2008 equivalents. Those properties and methods that have the same name and behavior are not listed. All Visual Basic 2008 enumerations map to the System.Windows.Forms namespace unless otherwise noted.

This table provides links to topics explaining behavior differences. Where there is no direct equivalent in Visual Basic 2008, links are provided to topics that present alternatives.

Properties

Visual Basic 6.0

Visual Basic 2008 Equivalent

ColorMode

New implementation. The SupportsColor property of the PrinterSettings class can be used to determine the color capabilities of a printer

Copies

Copies property of the PrinterSettings class.

CurrentX

CurrentY

New implementation. For more information, see Graphics for Visual Basic 6.0 Users.

DeviceName

PrinterName property of the PrinterSettings class.

DrawMode

DrawStyle

DrawWidth

New implementation. For details, see Graphics for Visual Basic 6.0 Users.

DriverName

New implementation. No longer needed; printer drivers are managed by Windows.

Duplex

Duplex property of the PrinterSettings class.

FillColor

FillStyle

New implementation. For details, see Graphics for Visual Basic 6.0 Users.

Font

FontBold

FontCount

FontItalic

FontName

Fonts

FontSize

FontStrikeThru

FontTransparent

FontUnderline

New implementation. For details, see Font Handling for Visual Basic 6.0 Users.

ForeColor

New implementation. For details, see Color Handling for Visual Basic 6.0 Users.

hDC

No longer necessary. An instance of a PrintDocument component is the equivalent of a device context.

Height

PaperSize property of the PageSettings class.

Orientation

Landscape property of the PageSettings class.

Page

New implementation. The current page number is not tracked; however, you can easily do this by setting a variable in the BeginPrint event and incrementing it in the PrintPage event.

PaperBin

PaperSources property of the PrinterSettings class.

PaperSize

PaperSize property of the PageSettings class.

Port

No longer necessary. The PrintPreviewDialog control automatically sets port information.

PrintQuality

PrinterResolutions property of the PrinterSettings class.

RightToLeft

No longer necessary. The direction of printing is controlled by the localization settings in Windows.

ScaleHeight

ScaleLeft

ScaleMode

ScaleTop

ScaleWidth

New implementation. For details, see Coordinate System for Visual Basic 6.0 Users.

TrackDefault

No direct equivalent. The IsDefaultPrinter property of the PrinterSettings class can be used to determine if a printer is the default.

TwipsPerPixelX

TwipsPerPixelY

No longer necessary. Measurements in Visual Basic 2005 are always in pixels.

Width

PaperSize property of the PageSettings class.

Zoom

No longer necessary. If the printer has zoom capabilities, settings are automatically exposed in the Print dialog box.

Methods

Visual Basic 6.0

Visual Basic 2008 Equivalent

Circle

New implementation. For more information, see Graphics for Visual Basic 6.0 Users.

EndDoc

Print

KillDoc

Cancel

Line

New implementation. For more information, see Graphics for Visual Basic 6.0 Users.

NewPage

HasMorePages

PaintPicture

PSet

New implementation. For more information, see Graphics for Visual Basic 6.0 Users.

Scale

ScaleX

ScaleY

New implementation. For details, see Coordinate System for Visual Basic 6.0 Users.

TextHeight

TextWidth

New implementation. For more information, see Graphics for Visual Basic 6.0 Users.

Upgrade Notes

When a Visual Basic 6.0 application is upgraded to Visual Basic 2008, all instances of the Printer object are upgraded to the Visual Basic 2008 Printer object.

See Also

Tasks

Printing Sample

Concepts

Printing Changes for Visual Basic 6.0 Users

Graphics for Visual Basic 6.0 Users

Reference

PageSettings

PrinterSettings

Other Resources

Windows Forms Print Support