Printers Collection for Visual Basic 6.0 Users

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

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 2008, 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.

Note

Visual Basic 2008 has a Printers collection that enables upgraded Visual Basic 6.0 Printer code to run without modification. For any new development, you should use the PrinterSettings class.

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

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
Next
' Visual BasicDim i AsIntegerDim pkInstalledPrinters AsStringFor i = 0 To System.Drawing.Printing.PrinterSettings. _
  InstalledPrinters.Count - 1

  pkInstalledPrinters = System.Drawing.Printing.PrinterSettings. _
    InstalledPrinters.Item(i)
  ListBox1.Items.Add(pkInstalledPrinters)
Next

Upgrade Notes

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

See Also

Concepts

Printing Changes for Visual Basic 6.0 Users

Reference

PrintDialog Component Overview (Windows Forms)

PrinterSettings

Other Resources

Windows Forms Print Support