An Overview of Wizards
A programmer's work can be repetitive. There's plenty of new, innovative code to write, but a lot of code is common to all projects. Rather than writing this code over and over, you can use a wizard to generate the starter code and start writing the core implementation of a project. A wizard can display a dialog box to walk the user through a set of steps, asking questions, and it uses the answers to make a complicated or often-repeated task easier to complete. Alternatively, a wizard can skip displaying a dialog box and simply generate code without asking the user for any input. Windows is full of wizards, such as wizards that help connect to printers and networks and even ones to find help when something goes wrong. Visual Studio .NET, on the other hand, uses wizards to generate code.
Types of Wizards
You can build and run three types of wizards in Visual Studio .NET. The type that's probably the most familiar to developers is the New Project wizard. A New Project wizard, as its name suggests, generates the code for a project that gives the user a starting point for a new program. New Project wizards are invoked when the user selects an item in the right panel of the New Project dialog box, which is displayed by choosing File | New | Project.The second type of wizard is an Add New Item wizard. Once a project has been created, a user often needs to add new files, such as classes, images, or Web pages, to that project. An Add New Item wizard can be used to create these new files. The common way to access this type of wizard is by right-clicking on a project in the Solution Explorer window and choosing Add | Add New Item. This displays the Add New Item dialog box, from which wizards can be run.The third and least-often used wizard type is a Custom wizard. A Custom wizard isn't invoked directly by Visual Studio .NET; rather, it is explicitly called by a macro, an add-in, or another wizard. A Custom wizard can't be classified as an Add New Item wizard or a New Project wizard, but it can walk the user through a set of steps to accomplish some task. With a Custom wizard, you can add wizard-like functionality anywhere within Visual Studio .NET and not be limited only to creating new projects or adding new files to an existing project, as you are with New Project or Add New Item wizards.Whether you choose to create a New Project, Add New Item, or Custom wizard, you implement it in the same basic way: you create a COM object that implements the wizard, you create a .vsz file to let Visual Studio .NET know about your wizard, and then you create the source code templates. We'll discuss each of these wizard types in this chapter as well as how to build them.