O'Reilly logo

Visual Basic 2005 Cookbook by Tim Patrick, John Clark Craig

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 11. Printing

Introduction

If there is one thing the typical business computer user needs more than anything else, it’s reports. Any readers who have worked in the IS or IT department of a large organization can quickly attest to that. And reports mean printing, and printing means pain. At least, that’s what I’ve always found. Certainly, there are many third-party reporting tools available, such as the version of Crystal Reports included with Visual Studio. But these “banded” reports don’t always meet your needs. Sometimes you need to print out some text or graphics formatted in unique and custom ways.

Fortunately, the printing tools included with .NET are powerful, easy to use, and—dare I say it—fun. All of the text and graphics tools you use to update the display with .NET’s GDI+ library can be leveraged for printing purposes. The printing commands aren’t just similar to those used for screen updates; they’re actually the same commands. (Chapter 9 includes many examples that use the graphics tools included with GDI+, so such examples won’t be replicated in this chapter.)

11.1. Enumerating Printers

Problem

You want to access a list of the printers available to the current Windows user.

Solution

The “printing” section of GDI+, the .NET drawing system, includes a list of the installed printers. Use the following code to display the names of each:

	For Each printerName As String In _
	      System.Drawing.Printing.PrinterSettings.InstalledPrinters
	   MsgBox(printerName)
	Next printerName

Discussion ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required