Appendix I. Visual Basic Power Packs

When Visual Basic .NET first appeared, it was missing many features that developers had found extremely useful in Visual Basic 6. Power Packs were invented to provide objects and tools to fill the need for these missing tools and to make programming easier and more productive in general.

This appendix describes Visual Basic Power Packs provided by Microsoft and others that you make find useful.

It also briefly describes some older Power Packs that were available from the GotDotNet web site. Although these were written in an older version of Visual Basic .NET, they may still be useful, at least as inspiration for tools you may want to build.

Finally, this appendix explains where you can find the Power Toys Pack Installer, a tool that lets you view, download, and install the latest Power Toys for Visual Studio.

MICROSOFT POWER PACKS

Originally Microsoft provided its Power Packs as a download but in Visual Basic 2010 they are included within Visual Basic. That doesn't mean you can instantly use them, however. By default, the Power Pack is installed but its tools are not included in new Visual Basic projects.

To use these tools, start a new project, open Solution Explorer, and double-click My Project to open the project property pages. On the References tab, click the Add button and add a reference to Microsoft.VisualBasic.PowerPacks.vs. This allows you to use the tools in your code and places the tools on the Windows Forms Designer's Toolbox with the other controls.

The Microsoft Visual Basic Power Packs 3.0 download includes DataRepeater, line and shape controls, plus a PrintForm and Printer Compatibility Library. The printer tools are mostly intended to help developers upgrade applications from Visual Basic 6 to Visual Basic .NET but they can be useful for new Visual Basic 2010 programs, too. The following sections describe the Power Pack tools in greater detail. For more information about these tools, go to the Microsoft Power Packs homepage msdn.microsoft.com/vbasic/aa701257.aspx.

DataRepeater

The DataRepeater control allows you to define a template of controls to display a piece of data. The repeater then repeats your template for each row in a data source and displays the result in a scrollable container.

Line and Shape Controls

The LineShape, OvalShape, and RectangleShape controls let you easily place lines, ovals, and rectangles on a form without using pens, brushes, and Graphics objects.

Properties let you set the controls' pens and brushes at design time. The controls support events such as Click and DoubleClick, and many of the graphical methods provided in the System.Drawing namespace. The OvalShape and RectangleShape controls even support linear gradient brushes that let you add interesting graphical effects at design time.

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. The library defines a Printer class. You can create a new Printer object and then use it much as you would use Visual Basic 6's Printer object.

See Chapter 34 for more information on printing in Visual Basic 2010.

My book Expert One-on-One Visual Basic Design and Development (Stephens, Wrox, 2005) includes a chapter on printing that explains how to print images of forms much as the PrintForm Power Pack component does. It also shows how to wrap text so it flows around images on a printed page and how to use metafiles to let a program print procedurally rather than by responding to events. For more information, see the book's web site at www.wrox.com or www.vb-helper.com/one_on_one.htm.

PrintForm Component

In Visual Basic 6 and earlier versions, the Form control have a PrintForm method that sends an image of the form to the printer. The result is a bitmap imagethat usually looks grainy on the printout. It does not take full advantage of the printer's high resolution, and it doesn't add extra data that can't fit on the monitor but that can fit 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.

The PrintForm component enables a Visual Basic .NET application to print a form's image quickly and easily.

GOTDOTNET POWER PACK

The GotDotNet Visual Basic Power Pack includes seven useful controls. While they were written in Visual Basic 2003, they can still be useful. The Power Pack comes with source code so you can upgrade them to Visual Basic 2010 or use their code as a starting point for building your own controls.

The following list summarizes the seven controls:

  • BlendPanel — Provides a background with linear gradient shading. Note that the WPF LinearGradientBrush class provides a similar, but more flexible, effect. Other WPF classes such as RadialGradientBrush provide even more shading features.

  • UtilityToolbar — A toolbar that has a look and feel similar to the Microsoft Internet Explorer toolbar.

  • ImageButton — A button with a transparent background. You can use it, for example, to display a round button over a gradient shaded, or complex background, without messing up the background.

  • NotificationWindow — Displays text and graphics in a popup notification window.

  • TaskPane — A container that provides collapsible panes similar to the WPF Expander control.

  • FolderViewer — Displays a hierarchical view of a directory tree.

  • FileViewer — Displays a list of the files in a directory.

Unfortunately, Microsoft closed the GotDotNet web site in 2007. Before the site disappeared, however, I saved a copy of the Power Pack. You can get more information and download it at www.vb-helper.com/tip_gotdotnet_powerpack.html.

POWER TOYS PACK INSTALLER

The Power Toys Pack Installer is a tool that lets you view, download, and install the latest Power Toys for Visual Studio. The "toys" include code snippets, starter kits, examples, and other tools divided into categories such as Visual Basic 2005, Visual Basic 6.0, C#, Printing, Interop, and Debugging.

You can learn more about the installer and download it at www.codeplex.com/PackInstaller.

REFACTOR!

Refactor! is a free plug-in developed by Developer Express Inc. that provides refactoring tools that can help you rearrange and restructure your code. For example, they can extract a section of code into a new routine, reorder a routine's parameters, or convert methods to properties and vice versa.

You can find a link to information about Refactor! at the Basic Developer Center. You can also learn about it on Developer Express's Refactor! web page www.devexpress.com/Products/Visual_Studio_Add-in/VBRefactor.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.189.189.220