Chapter 7 Advanced Printing

Team Fly 

Page 159

Chapter 7
Advanced Printing

AMONG THE MOST VISIBLE features introduced to VB.NET are the improved printing and print previewing mechanisms of .NET. You'll find it very easy to write your own printing routines, and the same code will produce both printouts and previews. To access the printing capabilities of .NET, you must use a few new controls. There's no longer a Printer object; you must use one of the controls that facilitate printing, and we examine these special controls in depth in the chapter. These controls can't be used to build interfaces; they simply expose the printing functionality of .NET to your application.

While printing has gotten both simpler and more powerful in VB.NET, the Windows controls we use to build our interfaces don't support printing. None of the controls that come with .NET provide a Print method, not even the TextBox control. Most developers will sooner or later face the problem of generating simple (or not so simple) printouts for their applications, and they'll have to write their own printing code. The other alternative is to buy a third-party control that supports printing, which is the suggested course of action if you need to print formatted text, but most developers will be handling simple printing tasks.

This chapter doesn't contain only advanced printing topics. It starts with an overview of the printing process in the .NET Framework (a process that's entirely different from the equivalent VB6 process) and it also covers simple topics such as printing text. The reason we've included this seemingly trivial topic is that we haven't found a reliable tool for printing text. Even the TextBox control doesn't provide a Print method, so we felt that a solid explanation of the process of printing text is in order. And as you will see in the corresponding section, printing text isn't as trivial as you may have thought. To make the sample code a little more useful, we've added a Print method to the TextBox control.

Another very common task in business applications is the printing of tabular data. We've decided to demonstrate this topic by creating a class that can print the contents of a ListView control.

Printing in .NET

The basic printing component in .NET is the PrintDocument control. To send something to the printer, you must first add an instance of the PrintDocument control to the project. This control is invisible at runtime and its icon appears on the Components tray at design time. To initiate the

Team Fly 


Visual Basic  .NET Power Tools
Visual Basic .NET Power Tools
ISBN: 0782142427
EAN: 2147483647
Year: 2003
Pages: 178

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net