Appendix I : Visual Basic Power Packs


Power Packs are objects and tools that can make programming easier and more productive. This appendix describes the Visual Basic 2005 Power Packs available from Microsoft. It also briefly describes some older Visual Basic 2003 Power Packs available from the GotDotNet web site. Although these were written in Visual Basic 2003, they may still be useful, at least as inspiration for tools you may want to build.

Microsoft Power Packs

Currently, the Microsoft Power Packs home page (msdn2.microsoft.com/vbasic/ aa701257.aspx) includes three tools. These are compatibility tools that make upgrading from Visual Basic 6 to Visual Basic .NET easier.

In addition to links to the three tools, this page includes a link to the Visual Basic Power Pack Suggestion Center where you can suggest new Power Packs, learn about tools that are still under development, and tell Microsoft which Power Packs you think would be most useful. For example, this page currently lets you vote on whether Microsoft should build Data Repeater, Line, and Shape controls similar to those provided in Visual Basic 6.

The following sections describe the three currently available tools.

Printer Compatibility Library

In Visual Basic 6 and earlier versions, programs used the Printer object to generate printouts. Programs used the object’s properties to define printing characteristics, and called its methods to draw on the printed page. Methods let you draw shapes, text, and images. Other methods let you start a new page, cancel the print document, or finish printing and send the results to the printer.

Visual Basic .NET uses a very different printing model. Instead of calling a Printer object’s methods, the program creates a PrintDocument object and then responds to that object’s events. When the object needs to generate a page, it raises an event and the program responds. Instead of actively telling the Printer object what to do, the program reactively responds to requests from the PrintDocument object.

The Printer Compatibility Library provides a way for Visual Basic .NET applications to print in a manner that is similar to the one used by Visual Basic 6. You add a reference to the library, create a Printer object, and use its methods to generate the printout.

See Chapter 24 for more information on printing in Visual Basic 2005. That chapter also describes another method for using metafiles to generate printouts procedurally, rather than in response to events.

Interop Forms Toolkit

It can be very expensive to rewrite large Visual Basic 6 applications in Visual Basic 2005. The Interop Forms Toolkit makes it easier to gradually upgrade such an application by adding Visual Basic .NET forms to it. (Interop is short for interoperability.)

The toolkit lets you build new forms in Visual Basic 2005 so that you don’t need to rewrite them later. It also lets you gradually rebuild existing forms to eventually convert the application to Visual Basic .NET. Although it is likely that you will eventually need to rewrite code that connects the Visual Basic 6 and Visual Basic .NET portions to complete the transition, this toolkit can let you approach the problem in pieces, instead of performing a single massive rewrite.

PrintForm Component

In Visual Basic 6 and earlier versions, the Form control had a PrintForm method that sent an image of the form to the printer. The result was a bitmap image that usually looked grainy on the printout. It did not take full advantage of the printer’s high resolution, and it didn’t add extra data that doesn’t fit on the monitor, but that usually fits on a printout.

However, PrintForm is extremely easy to use. The program simply calls the form’s PrintForm method. This is much simpler than generating a high-resolution printout, so developers often use it to give early versions of an application a printing capability. For many applications, PrintForm is good enough, and it gives users a WYSIWYG (what you see is what you get) printing tool, so that’s all the program needs.

This component enables a Visual Basic .NET application to print a form’s image quickly and easily.

Note also that you can use the Form object’s DrawToBitmap method to capture an image of the form in a bitmap. You can then print the image, save it into a file, or do anything else that you can do with a bitmap. For an example, see www.vb-helper.com/howto_2005_drawtobitmap.html.




Visual Basic 2005 with  .NET 3.0 Programmer's Reference
Visual Basic 2005 with .NET 3.0 Programmer's Reference
ISBN: 470137053
EAN: N/A
Year: 2007
Pages: 417

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