<!-- Download Links -->
<!-- Article image -->
<!-- Add the rest of your HTML here -->
Some month that I have started to develop with .NET framework and C#. Used to
MFC, I was very disappointed to not found a class to make a wizard. I’ve
checked the web, and found the wizard framework of James T. Johnson. But, in
fact, I found it a little complicated to use and design, so I’ve developed my
own. The idea, is to ease the design of the wizard and re-use MFC concept.
With MFC, the creation of a wizard was the same process than create tab
control and tab page. So, I’ve decided to reuse the Visual Studio .NET wizard
to create Tab control, and work around.
The final result is a dialog, with an empty tab control that must be inherited.
At design time, the developer create tab page and fill them with the control
that he wants. At run time, the dialog act as a wizard, hiding the tab control.
Design of a simple wizard
Inheritance of dialog wizard
Use the “Add inherited form” wizard in Visual Studio.net, and select the
in the inheritance picker dialog.
You have the following form in your project:
The tab control is empty, but you see the 4 essential buttons : “Cancel”,
”Back”, “Next” and “Finish”.
Create the pages of the wizard, as you create page for a tab control. Take in
mind that the order of the page will be the order of the page in the wizard.
For each tab page, set the text to the text that describe the step of the
wizard. This text will appear in the title of the wizard at run time.
Implement ActivatePage method
ActivatePage method is called automatically before a page is
displayed. This method have the zero based number of the displayed page as
parameter. The developer must implement this method to do all the
initialization task of a page. This method is called only one time per page.
UnActivatePage is used to deactivate a page, to
ActivatePage will be called again if the user go back
protected override void ActivatePage(int piPageNumber)
DataTable oTable = new DataTable();
Implement ValidatePage method
method is called when the user use the “Next” or
“Finish” button. The number of the current page is in the integer parameter.
This method must return
if the page is validated. If this
, the “next” or “Finish” button doesn’t do
anything, until the page is validated.
Simply use the ShowDialog method to show the wizard. It would start by the
first tab page. Clicking on the “Finish” button will end the wizard, but
would use the
ValidatePage for each
Since the Wizard is inherited, you can freely customize the base dialog, button
and tab control. Just keep in mind that the tab control is hidden, and the
underlying tab page, resized to fill the space used by the tab control.
You can also add button anywhere on the drawing surface of the dialog to
your own purpose.
protected override bool ValidatePage(int piPageNumber)
if (textBox1.Text != string.Empty & textBox2.Text != string.Empty)
MessageBox.Show(this, "Complete data first");
Other methods used
This method is used, when the user use the “Back” button, to deactivate a page,
be called again.
is the number of the page that must be deactivated.
This method is called to allow or disallow the back button in the wizard. The
default behaviour is back enabled.
This method can be overloaded. This method increment the number of the
displayed page. The default, is an increment by 1. Overload this method if you
want to jump over pages.
This method as the same function as
, but decrement
the displayed page by 1 per default. Overload this method to have a different