Click here to Skip to main content
15,893,668 members
Articles / Desktop Programming / Windows Forms
Article

Wizard like application using Windows.Forms.TabControl

Rate me:
Please Sign up or sign in to vote.
1.19/5 (12 votes)
6 Jun 20072 min read 26.6K   14   2
Creating wizard like application using Windows.Forms.TabControl

Introduction

This article will explain how to make wizard like application by using Windows.Forms.TabControl .NET control.

I will provide only necessary inline code, because I will talk more about architecture.
(Please forgive my english)

Background

Recently I read article A simple Wizard control for .Net 2.0 with full designer support By Manish Ranjan Kumar. He developed very useful component for wizards where the app logic is like Start -> Next -> .. -> Finish. But what to do when we need more personalized behavior?

Description

I decided to use TabControl control because of its pages and therefore good design time support when creating steps in our wizard. So it is easy - each page is one step in wizard process. Wizards usually have at least two buttons: Next and Back. We can put it outside of TabControl to make them common, or inside in each page in case of count of buttons or their labels vary by page (step).

The problem is only how to hide tab's title and do not allow to change tabs by user will. Both is easy. We can hide tabpages putting Panel control (or something else) over this buttons. This also disables switching tabs by mouse. To disable switching them by keys, we simply add following code:

C#
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
    if (ActiveControl is TabControl)
    {
        if (System.Convert.ToBoolean(keyData & Keys.Tab | Keys.Control))
            return true;
    }
    return base.ProcessCmdKey (ref msg, keyData);
}

which override form key handler in case of TabControl. And it is finished. We can make application logic as complicated as we need :)

Some usefull tips

I created many wizards using this structure, some were easy and some more difficult, and here I some tips I can remember while I was developing them:
- Adjust the height of "overlapping panel" programmatically, so you can switch tabs in design time by mouse...
- If the background of each tab is same, set it programmatically, because when set in designer, the bitmap will appear in your resources many times.
(I was doing it by setting bg on one tab, then copy generated key with value to new resource file, and then set it on Form_Load for each tab, see code below.

C#
ResourceManager resManager = new ResourceManager("namespace.filename", this.GetType().Assembly);
Bitmap imgMain = (Bitmap)resManager.GetObject("resourcekey");
resManager.ReleaseAllResources();
foreach (TabPage tab in tabControl1.TabPages) tab.BackgroundImage = imgMain;

History

No updates

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


Written By
Slovakia Slovakia
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralGreat! Pin
Alimnios728-Sep-11 9:19
Alimnios728-Sep-11 9:19 
Generalexample Pin
blackjack215011-Jun-07 21:57
blackjack215011-Jun-07 21:57 

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

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