Click here to Skip to main content
Click here to Skip to main content

Another wizard for .NET using tab control

, 21 Dec 2002
Rate this:
Please Sign up or sign in to vote.
Another wizard for .NET using tab control
<!-- Download Links --> <!-- Article image -->

Sample Image - WizardForm.jpg

<!-- Add the rest of your HTML here -->

Introduction

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 WizardForm 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”.

Creating pages

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

The 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.

Another method, UnActivatePage is used to deactivate a page, to allow the ActivatePage will be called again if the user go back and forward.

protected override void ActivatePage(int piPageNumber) 
{
  switch (piPageNumber)
  { 
    case 1: 
      DataTable oTable = new DataTable();

      // Do some stuff to init the page
      break; 
  } 
}

Implement ValidatePage method

The ValidatePage 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 true if the page is validated. If this method return false, the “next” or “Finish” button doesn’t do anything, until the page is validated.

Run wizard

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 ActivatePage and ValidatePage for each remaining page.

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) 
{ 
  switch (piPageNumber) 
  { 
    case 0: 
      if (textBox1.Text != string.Empty & textBox2.Text != string.Empty) 
        return true; 
      MessageBox.Show(this, "Complete data first"); 
      return false; 
  } 
  return true; 
} 

Other methods used

UnActivatePage

This method is used, when the user use the “Back” button, to deactivate a page, so the ActivatePage be called again. piPageNumber parameter is the number of the page that must be deactivated.

AllowBack

This method is called to allow or disallow the back button in the wizard. The default behaviour is back enabled.

ForwardOffset

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.

PreviousOffset

This method as the same function as ForwardOffset , but decrement the displayed page by 1 per default. Overload this method to have a different behaviour. 

History

December 2002

  • Initial posting

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

nimbus3d
Software Developer (Senior)
France (Metropolitan) France (Metropolitan)
No Biography provided

Comments and Discussions

 
QuestionLicense PinmemberPostremus1-Jan-13 4:10 
AnswerRe: License Pinmembernimbus3d4-Jan-13 22:04 
GeneralResize Warning .net 2.0 PinmemberClermond25-Dec-05 4:53 
GeneralFranework to Wizard from VBPJ Pinmembertengtium7-Mar-05 1:53 
GeneralCreating Tab Index PinsussAnonymous3-Dec-04 20:38 
GeneralResize the wizard PinmemberTsjaar26-Oct-04 2:45 
GeneralRe: Resize the wizard Pinmembermiqel8-Feb-11 0:30 
GeneralTab control PinmemberDeepkiss24-May-03 1:58 
GeneralTab control PinmemberDeepkiss24-May-03 1:49 
GeneralRe: Tab control Pinmembernimbus3d24-May-03 2:23 
Hi,
If you look the source code, u would see that the CtrlTab control is hidden.
The pages of the control are showed "by hand" while the user press on next or previous button.
Regards

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web04 | 2.8.140721.1 | Last Updated 22 Dec 2002
Article Copyright 2002 by nimbus3d
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid