Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Printers Collection for Visual Basic 6.0 Users
Collapse the table of content
Expand the table of content

Printers Collection for Visual Basic 6.0 Users 

The Visual Basic 6.0 Printers collection has no direct equivalent in Visual Basic 2005.

Conceptual Differences

In Visual Basic 6.0, the Printers collection is used to return information about available printers on a system. Typically, you iterate through the Printers collection to find a printer with certain attributes and then set that printer to be the default printer for your application. For example, you might choose a laser printer instead of a dot matrix printer.

In Visual Basic 2005, there is no direct equivalent for the Printers collection, and the model has changed: Rather than choosing a printer for your application, you should allow your users to make their own choices.

A PrintDialog component can be used to present a list of available printers to the user. Properties for the printer selected by the user can be retrieved using the PrinterSettings class.

The Printers collection in Visual Basic 6.0 has two properties: Item and Count. The PrintDialog component has no equivalent properties. The PrinterSettings class has an InstalledPrinters collection with Item and Count; however, this is a String collection and cannot be used to query the attributes of a printer.

Code Changes for the Printers Collection

The following code example illustrates the differences in coding techniques between Visual Basic 6.0 and Visual Basic 2005.

Code Changes for Returning a List of Available Printers

The following example demonstrates populating a ListBox control with a list of available printers.

' Visual Basic 6.0
Dim X As Printer
For Each X In Printers
    List1.AddItem X.DeviceName
' Visual Basic 2005
Dim i As Integer
Dim pkInstalledPrinters As String
For i = 0 To System.Drawing.Printing.PrinterSettings. _
  InstalledPrinters.Count - 1

  pkInstalledPrinters = System.Drawing.Printing.PrinterSettings. _

Upgrade Notes

When a Visual Basic 6.0 application is upgraded to Visual Basic 2005, any instances of the Printers collection are not upgraded and an upgrade error is issued. You will need to remove the code for the Printers collection and modify your code so that it uses a PrintDialog component.

See Also

Community Additions

© 2015 Microsoft